{"id":1364,"date":"2018-01-19T19:22:45","date_gmt":"2018-01-19T19:22:45","guid":{"rendered":"http:\/\/goofy-trucks.flywheelsites.com\/variable-variables-page-2\/"},"modified":"2018-01-19T19:24:44","modified_gmt":"2018-01-19T19:24:44","slug":"variable-variables-page-2","status":"publish","type":"post","link":"https:\/\/phpbuilder.com\/variable-variables-page-2\/","title":{"rendered":"Variable Variables Page 2"},"content":{"rendered":"<div class=\"phpbuilder-content\">\n<div class=\"phpbuilder-meta\">\n<div class=\"\">By Robert Berkowitz<\/div>\n<div class=\"\">on September 28, 2000<\/div>\n<\/p><\/div>\n<div id=\"overflow-content\">\n<h2>Example<\/h2>\n<div class=\"articlePara\">\nLet&#8217;s say you have a MySQL database that stores link submissions for sites of interest.<br \/>\nIn that database there is a table called submissions.  The fields in the submissions table are as follows:<\/div>\n<div class=\"example\">\n<pre>\n\tSubmissionID\n\tPostedBy\n\tLink\n\tDescription\n\tApproved\n<\/pre>\n<\/div>\n<div class=\"articlePara\">\nYou want to be able to display all the submissions that have been made but are not yet approved in<br \/>\na table.  The editor will then be able to correct any typing mistakes, select the proper radio<br \/>\nbutton next to each link for approval, and submit them all at once.<\/div>\n<div class=\"articlePara\">\nFirst, when you pull the data from the database and display it on the page you must set each name<br \/>\nfor every record to be unique.  This will enable us to loop through the records and be able to<br \/>\nidentify what value goes where once the submit button has been pressed.  To do this we do the following:<\/div>\n<div class=\"articlePhpEx\">\n<font face=\"courier\"><code><span style=\"color: #000000\"><\/p>\n<p><span style=\"color: #0000BB\">&lt;?php<\/p>\n<p><\/span><span style=\"color: #FF8000\">\/\/Initialize\u00a0counter\u00a0variables<\/p>\n<p><\/span><span style=\"color: #0000BB\">$index\u00a0<\/span><span style=\"color: #007700\">=\u00a0<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">;<br \/>\n<br \/><\/span><span style=\"color: #0000BB\">$index_count\u00a0<\/span><span style=\"color: #007700\">=\u00a0<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">;<\/p>\n<p>echo\u00a0<\/span><span style=\"color: #DD0000\">\"&lt;form\u00a0method=post\u00a0action=$PHP_SELF&gt;n\"<\/span><span style=\"color: #007700\">;<br \/>\n<br \/>echo\u00a0<\/span><span style=\"color: #DD0000\">\"&lt;table&gt;n\"<\/span><span style=\"color: #007700\">;<br \/>\n<br \/>echo\u00a0<\/span><span style=\"color: #DD0000\">\"&lt;tr&gt;&lt;td&gt;&lt;b&gt;Posted\u00a0By&lt;\/b&gt;&lt;\/td&gt;&lt;td&gt;&lt;b&gt;Link&lt;\/b&gt;&lt;\/td&gt;\"<\/span><span style=\"color: #007700\">.<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #DD0000\">\"&lt;td&gt;&lt;b&gt;Description&lt;\/b&gt;&lt;\/td&gt;&lt;td&gt;&lt;b&gt;Approved&lt;\/b&gt;&lt;\/td&gt;&lt;\/tr&gt;n\"<\/span><span style=\"color: #007700\">;<\/p>\n<p><\/span><span style=\"color: #FF8000\">\/*<br \/>\n<br \/>Assuming\u00a0we\u00a0already\u00a0have\u00a0retrieved\u00a0the\u00a0records\u00a0from\u00a0the\u00a0database\u00a0into\u00a0an\u00a0array\u00a0setting\u00a0<br \/>\n<br \/>$myrow\u00a0=\u00a0mysql_fetch_array().\u00a0\u00a0The\u00a0do...while\u00a0loop\u00a0assigns\u00a0a\u00a0value\u00a0to\u00a0the\u00a0$xstr\u00a0variable\u00a0<br \/>\n<br \/>by\u00a0taking\u00a0the\u00a0name\u00a0and\u00a0concatenating\u00a0the\u00a0value\u00a0of\u00a0$index\u00a0to\u00a0the\u00a0end\u00a0starting\u00a0with\u00a00.\u00a0\u00a0So\u00a0<br \/>\n<br \/>the\u00a0first\u00a0time\u00a0through\u00a0the\u00a0loop\u00a0$SubmissionIDStr\u00a0would\u00a0have\u00a0a\u00a0value\u00a0of\u00a0SubmissionID0\u00a0the\u00a0<br \/>\n<br \/>next\u00a0time\u00a0through\u00a0it\u00a0would\u00a0be\u00a0SubmissionID1\u00a0and\u00a0so\u00a0forth.<br \/>\n<br \/>*\/<\/p>\n<p><\/span><span style=\"color: #007700\">do\u00a0{<\/p>\n<p><\/span><span style=\"color: #0000BB\">$SubmissionIDStr\u00a0<\/span><span style=\"color: #007700\">=\u00a0<\/span><span style=\"color: #0000BB\">SubmissionID<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$index<\/span><span style=\"color: #007700\">;<br \/>\n<br \/><\/span><span style=\"color: #0000BB\">$PostedByStr\u00a0<\/span><span style=\"color: #007700\">=\u00a0<\/span><span style=\"color: #0000BB\">PostedBy<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$index<\/span><span style=\"color: #007700\">;<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #0000BB\">$LinkStr\u00a0<\/span><span style=\"color: #007700\">=\u00a0<\/span><span style=\"color: #0000BB\">Link<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$index<\/span><span style=\"color: #007700\">;<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #0000BB\">$DescriptionStr\u00a0<\/span><span style=\"color: #007700\">=\u00a0<\/span><span style=\"color: #0000BB\">Description<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$index<\/span><span style=\"color: #007700\">;<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #0000BB\">$ApprovedStr\u00a0<\/span><span style=\"color: #007700\">=\u00a0<\/span><span style=\"color: #0000BB\">Aprroved<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$index<\/span><span style=\"color: #007700\">;<\/p>\n<p><\/span><span style=\"color: #FF8000\">\/\/This\u00a0section\u00a0would\u00a0print\u00a0the\u00a0values\u00a0onto\u00a0the\u00a0screen\u00a0one\u00a0record\u00a0per\u00a0row<\/p>\n<p><\/span><span style=\"color: #0000BB\">printf<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"&lt;tr&gt;&lt;td&gt;&lt;input\u00a0type=hidden\u00a0name=%s\u00a0value=%s&gt;&lt;input\u00a0type=text\u00a0name=%s\u00a0value=%s&gt;&lt;\/td&gt;<br \/>\n<br \/>&lt;td&gt;&lt;input\u00a0type=text\u00a0name=%s\u00a0value=%s&gt;&lt;\/td&gt;&lt;td&gt;&lt;input\u00a0type=text\u00a0name=%s\u00a0value=%s&gt;&lt;\/td&gt;<br \/>\n<br \/>&lt;td&gt;&lt;input\u00a0type=radio\u00a0name=%s\u00a0value=-1&gt;Yes&lt;input\u00a0type=radio\u00a0name=%s\u00a0value=0\u00a0checked&gt;No&lt;\/td&gt;&lt;\/tr&gt;n\"<\/span><span style=\"color: #007700\">,\u00a0<br \/>\n<br \/><\/span><span style=\"color: #0000BB\">$SubmissionIDStr<\/span><span style=\"color: #007700\">,\u00a0<\/span><span style=\"color: #0000BB\">$myrow<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">\"SubmissionID\"<\/span><span style=\"color: #007700\">],\u00a0<\/span><span style=\"color: #0000BB\">$PostedByStr<\/span><span style=\"color: #007700\">,\u00a0<\/span><span style=\"color: #0000BB\">$myrow<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">\"PostedBy\"<\/span><span style=\"color: #007700\">],\u00a0<\/span><span style=\"color: #0000BB\">$LinkStr<\/span><span style=\"color: #007700\">,\u00a0<\/span><span style=\"color: #0000BB\">$myrow<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">\"Link\"<\/span><span style=\"color: #007700\">],\u00a0<br \/>\n<br \/><\/span><span style=\"color: #0000BB\">$DescriptionStr<\/span><span style=\"color: #007700\">,\u00a0<\/span><span style=\"color: #0000BB\">$myrow<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">\"Description\"<\/span><span style=\"color: #007700\">],\u00a0<\/span><span style=\"color: #0000BB\">$ApprovedStr<\/span><span style=\"color: #007700\">,\u00a0<\/span><span style=\"color: #0000BB\">$ApprovedStr<\/span><span style=\"color: #007700\">);<\/p>\n<p><\/span><span style=\"color: #FF8000\">\/\/Increase\u00a0counter\u00a0values\u00a0by\u00a01\u00a0for\u00a0each\u00a0loop<\/p>\n<p><\/span><span style=\"color: #0000BB\">$index<\/span><span style=\"color: #007700\">++;<br \/>\n<br \/><\/span><span style=\"color: #0000BB\">$index_count<\/span><span style=\"color: #007700\">++;<\/p>\n<p>}\u00a0while\u00a0(<\/span><span style=\"color: #0000BB\">$myrow\u00a0<\/span><span style=\"color: #007700\">=\u00a0<\/span><span style=\"color: #0000BB\">mysql_fetch_array<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">));<\/p>\n<p><\/span><span style=\"color: #FF8000\">\/\/\u00a0I\u00a0also\u00a0had\u00a0to\u00a0create\u00a0an\u00a0index\u00a0count\u00a0to\u00a0keep\u00a0track\u00a0of\u00a0the\u00a0total\u00a0number\u00a0of\u00a0rows.<\/p>\n<p><\/span><span style=\"color: #007700\">echo\u00a0<\/span><span style=\"color: #DD0000\">\"&lt;INPUT\u00a0TYPE=hidden\u00a0NAME=counter\u00a0VALUE=$index_count&gt;n\"<\/span><span style=\"color: #007700\">;<\/p>\n<p>echo\u00a0<\/span><span style=\"color: #DD0000\">\"&lt;INPUT\u00a0TYPE=submit&gt;&lt;\/form&gt;n\"<\/span><span style=\"color: #007700\">;<\/p>\n<p><\/span><span style=\"color: #0000BB\">?&gt;<br \/>\n<br \/><\/span><br \/>\n<\/span><br \/>\n<\/code><\/font><\/div>\n<div class=\"articlePara\">\nAfter the submit button is pressed to we have to loop through all the variables on the page again.<br \/>\nWe are able to do this with the $index_count variable we created.  Next, we assign the value of<br \/>\nthose variables to yet another variable in the second step.  This is where variable variables come into play.<\/div>\n<\/div>\n<p><\/p>\n<div style=\"float: left; padding:15px; color:#17AAF3\">\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"robert20000928.html\">\u00ab Previous Page<\/a><\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"robert20000928.html\">1<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"background-color:#B6E5FC; font-size:16px; margin-top:1px; padding:1px 4px 1px 4px; color:#000; font-style:bold; float:left;\">2<\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"robert200009289ba9.html?page=3\">3<\/a> <\/div>\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"robert200009289ba9.html?page=3\">Next Page \u00bb<\/a><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>By Robert Berkowitz on September 28, 2000 Example Let&#8217;s say you have a MySQL database that stores link submissions for sites of interest. In that database there is a table called submissions. The fields in the submissions table are as follows: SubmissionID PostedBy Link Description Approved You want to be&#8230; <a href=\"https:\/\/phpbuilder.com\/variable-variables-page-2\/\" class=\"readmore\"><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1364","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/comments?post=1364"}],"version-history":[{"count":1,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1364\/revisions"}],"predecessor-version":[{"id":3239,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1364\/revisions\/3239"}],"wp:attachment":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/media?parent=1364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/categories?post=1364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/tags?post=1364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}