<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Populating a Select Box With PHP and MySQL &#8211; PHP Tutorial</title>
	<atom:link href="http://www.tech-evangelist.com/2007/11/22/php-select-box/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tech-evangelist.com/2007/11/22/php-select-box/</link>
	<description>Technical Articles, Musings and Opinions from Tech-Evangelist</description>
	<lastBuildDate>Sun, 29 Jan 2012 19:09:23 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Doogie</title>
		<link>http://www.tech-evangelist.com/2007/11/22/php-select-box/comment-page-1/#comment-23899</link>
		<dc:creator>Doogie</dc:creator>
		<pubDate>Tue, 17 Jan 2012 16:28:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.tech-evangelist.com/2007/11/22/php-select-box/#comment-23899</guid>
		<description>Hi Beosma

It doesn&#039;t matter if there is one word or multiple words. All of the words in the selected element get passed as a variable value. In the code above, that variable would be read like this:

if (isset($_POST[&#039;categoryID&#039;])) $categoryID = $_POST[&#039;categoryID&#039;]; else $categoryID = 0;

You could substitute the category name for the category ID in the code and it should assign it to $categoryID on the page that processes the form data.</description>
		<content:encoded><![CDATA[<p>Hi Beosma</p>
<p>It doesn&#8217;t matter if there is one word or multiple words. All of the words in the selected element get passed as a variable value. In the code above, that variable would be read like this:</p>
<p>if (isset($_POST['categoryID'])) $categoryID = $_POST['categoryID']; else $categoryID = 0;</p>
<p>You could substitute the category name for the category ID in the code and it should assign it to $categoryID on the page that processes the form data.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Beosma</title>
		<link>http://www.tech-evangelist.com/2007/11/22/php-select-box/comment-page-1/#comment-23895</link>
		<dc:creator>Beosma</dc:creator>
		<pubDate>Mon, 16 Jan 2012 18:40:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.tech-evangelist.com/2007/11/22/php-select-box/#comment-23895</guid>
		<description>Great code guys!  I already have the  code written to populate my drop down box from a MySQL query.  I want the value I click on to be used as a search parameter in a MySQL database.  My problem is that any value in the drop down box that is more than one word, doesnt work.  Why does this happen and how can I get around it?  I am assuming that the selection is treated as one variable, if it isn&#039;t, do I use an array to concatenate all the parts?  I am just stuck here and could really use some help.

I am using php to populate the list and calling another php file to process the search...which of course is coming up blank due to no matches!
Looking forward to some input here.  Thanks!</description>
		<content:encoded><![CDATA[<p>Great code guys!  I already have the  code written to populate my drop down box from a MySQL query.  I want the value I click on to be used as a search parameter in a MySQL database.  My problem is that any value in the drop down box that is more than one word, doesnt work.  Why does this happen and how can I get around it?  I am assuming that the selection is treated as one variable, if it isn&#8217;t, do I use an array to concatenate all the parts?  I am just stuck here and could really use some help.</p>
<p>I am using php to populate the list and calling another php file to process the search&#8230;which of course is coming up blank due to no matches!<br />
Looking forward to some input here.  Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doogie</title>
		<link>http://www.tech-evangelist.com/2007/11/22/php-select-box/comment-page-1/#comment-23854</link>
		<dc:creator>Doogie</dc:creator>
		<pubDate>Tue, 13 Dec 2011 12:41:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.tech-evangelist.com/2007/11/22/php-select-box/#comment-23854</guid>
		<description>Hi Abhay

If I understand you correctly, you want to substitute the word Any whenever a field is empty. You will still need an ID for a unique identifier, but if the text field is empty, you can test it and substitute the word Any. In the case of the code sample above, you could do something like this for the code within the WHILE loop. 

if(empty($row[&#039;category_name&#039;])) $catName = &quot;Any&quot;; else $catName = $row[&#039;category_name&#039;];
echo &quot;&lt;option value=\&quot;&quot;.$row[&#039;category_id&#039;].&quot;\&quot;&gt;&quot;.$catName.&quot;&lt;/option&gt;\n&quot;;

You may end up with multiple instances where the choice is &#039;Any&#039;.</description>
		<content:encoded><![CDATA[<p>Hi Abhay</p>
<p>If I understand you correctly, you want to substitute the word Any whenever a field is empty. You will still need an ID for a unique identifier, but if the text field is empty, you can test it and substitute the word Any. In the case of the code sample above, you could do something like this for the code within the WHILE loop. </p>
<p>if(empty($row['category_name'])) $catName = &quot;Any&quot;; else $catName = $row['category_name'];<br />
echo &quot;&lt;option value=\&quot;&quot;.$row['category_id'].&quot;\&quot;&gt;&quot;.$catName.&quot;&lt;/option&gt;\n&quot;;</p>
<p>You may end up with multiple instances where the choice is &#8216;Any&#8217;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abhay</title>
		<link>http://www.tech-evangelist.com/2007/11/22/php-select-box/comment-page-1/#comment-23849</link>
		<dc:creator>Abhay</dc:creator>
		<pubDate>Fri, 09 Dec 2011 10:38:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.tech-evangelist.com/2007/11/22/php-select-box/#comment-23849</guid>
		<description>Hi this is a great tutorial thanks, is there a way I populate the select box from database as shown and also incorporate &quot;Any&quot; that passes out empty value, so that the output gives all results when selected ANY or as per the selected one.

echo&quot;Any&quot;;

wasnt able to send an empty / null value..

sorry if i am not been able to put it perfectly, as am not an PHP expert, just trying to correct a given code..

Thanks
Abhay</description>
		<content:encoded><![CDATA[<p>Hi this is a great tutorial thanks, is there a way I populate the select box from database as shown and also incorporate &#8220;Any&#8221; that passes out empty value, so that the output gives all results when selected ANY or as per the selected one.</p>
<p>echo&#8221;Any&#8221;;</p>
<p>wasnt able to send an empty / null value..</p>
<p>sorry if i am not been able to put it perfectly, as am not an PHP expert, just trying to correct a given code..</p>
<p>Thanks<br />
Abhay</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://www.tech-evangelist.com/2007/11/22/php-select-box/comment-page-1/#comment-23297</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 13 Sep 2011 19:09:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.tech-evangelist.com/2007/11/22/php-select-box/#comment-23297</guid>
		<description>Thanks for this code. It works great. I want to add a hidden field based on the option selected but can&#039;t seem to get the code correct. This is what I have:-


    &lt;?php
$sql = &quot;SELECT ID_day, day FROM day &quot;.
&quot;ORDER BY ID_day&quot;;

$rs = mysql_query($sql);

while($row = mysql_fetch_array($rs))
{
  echo &#039;&#039;.$row[&#039;day&#039;].&quot;\n &quot;;

}
?&gt;


I want the page to also pass the ID_date field to the one selected.

Thanks

Steve</description>
		<content:encoded><![CDATA[<p>Thanks for this code. It works great. I want to add a hidden field based on the option selected but can&#8217;t seem to get the code correct. This is what I have:-</p>
<p>    &lt;?php<br />
$sql = &quot;SELECT ID_day, day FROM day &quot;.<br />
&quot;ORDER BY ID_day&quot;;</p>
<p>$rs = mysql_query($sql);</p>
<p>while($row = mysql_fetch_array($rs))<br />
{<br />
  echo &#039;&#8217;.$row['day'].&#8221;\n &#8220;;</p>
<p>}<br />
?&gt;</p>
<p>I want the page to also pass the ID_date field to the one selected.</p>
<p>Thanks</p>
<p>Steve</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: derpsn</title>
		<link>http://www.tech-evangelist.com/2007/11/22/php-select-box/comment-page-1/#comment-22657</link>
		<dc:creator>derpsn</dc:creator>
		<pubDate>Tue, 23 Aug 2011 10:02:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.tech-evangelist.com/2007/11/22/php-select-box/#comment-22657</guid>
		<description>great tutorial, was really helpfull!

but what if you have multiple entries with the same category? it will show you then the category to select for each individual one. any possibilities to group them togehter?

in my case im doing a sort by date. so i have a timestamp in the database which is like : 2011-08-23 08:45:01 which using substr will show me then the date only. but if there where 10 entries with that date i got like 10 times the same option.</description>
		<content:encoded><![CDATA[<p>great tutorial, was really helpfull!</p>
<p>but what if you have multiple entries with the same category? it will show you then the category to select for each individual one. any possibilities to group them togehter?</p>
<p>in my case im doing a sort by date. so i have a timestamp in the database which is like : 2011-08-23 08:45:01 which using substr will show me then the date only. but if there where 10 entries with that date i got like 10 times the same option.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ramiro</title>
		<link>http://www.tech-evangelist.com/2007/11/22/php-select-box/comment-page-1/#comment-22628</link>
		<dc:creator>Ramiro</dc:creator>
		<pubDate>Thu, 11 Aug 2011 12:49:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.tech-evangelist.com/2007/11/22/php-select-box/#comment-22628</guid>
		<description>Thank  you very much. The code is working.
Ramiro</description>
		<content:encoded><![CDATA[<p>Thank  you very much. The code is working.<br />
Ramiro</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: frank</title>
		<link>http://www.tech-evangelist.com/2007/11/22/php-select-box/comment-page-1/#comment-22620</link>
		<dc:creator>frank</dc:creator>
		<pubDate>Mon, 08 Aug 2011 11:18:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.tech-evangelist.com/2007/11/22/php-select-box/#comment-22620</guid>
		<description>Just to say that after days of struggling through the garbage that people put on the internet for the simplest things this explanation is super great fantastic clean simple works and I finally get it.  Thanks a zillion!</description>
		<content:encoded><![CDATA[<p>Just to say that after days of struggling through the garbage that people put on the internet for the simplest things this explanation is super great fantastic clean simple works and I finally get it.  Thanks a zillion!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles</title>
		<link>http://www.tech-evangelist.com/2007/11/22/php-select-box/comment-page-1/#comment-22218</link>
		<dc:creator>Charles</dc:creator>
		<pubDate>Thu, 30 Jun 2011 02:47:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.tech-evangelist.com/2007/11/22/php-select-box/#comment-22218</guid>
		<description>Hi All!

Would like to ask for your help. Im currently using a multiple select box and i&#039;m already done with the inserting part but i&#039;m having problems on populating the data the was inserted 

MySQL Data:
   A, B, C, D

how can i use the data to be inserted to the edit multiple select box?

Thanks Guys!</description>
		<content:encoded><![CDATA[<p>Hi All!</p>
<p>Would like to ask for your help. Im currently using a multiple select box and i&#8217;m already done with the inserting part but i&#8217;m having problems on populating the data the was inserted </p>
<p>MySQL Data:<br />
   A, B, C, D</p>
<p>how can i use the data to be inserted to the edit multiple select box?</p>
<p>Thanks Guys!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig Mazur</title>
		<link>http://www.tech-evangelist.com/2007/11/22/php-select-box/comment-page-1/#comment-22134</link>
		<dc:creator>Craig Mazur</dc:creator>
		<pubDate>Tue, 21 Jun 2011 13:32:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.tech-evangelist.com/2007/11/22/php-select-box/#comment-22134</guid>
		<description>@Martin

I don&#039;t know if any of your code got stripped out. WordPress has a tendency to do that.  I don&#039;t see the HTML option code in the sample code that you submitted. 

If you want to retrieve the selected value from the select box used in ther example, use the following PHP code on the page that the form gets submitted to.  This will retrieve the selected value from categoryID and plug it into a variable named $categoryID. This assumes that you are using the POST method. 

if (isset($_POST[&#039;categoryID&#039;])) $categoryID = $_POST[&#039;categoryID&#039;];

If you are trying to retain the selected value from the drop-down and display that if the form fails the error checking, then you need to change the code for line with the the option tag. Split the line with the option code into three lines.

  echo &quot;&lt;option value=&#092;&quot;&quot;.$row[&#039;category_id&#039;].&quot;&#092;&quot;&quot;;
  if ($categoryID == $row[&#039;category_id&#039;]) echo &quot; selected=\&quot;selected\&quot;&quot;;
  echo &quot;&gt;&quot;.$row[&#039;category_name&#039;].&quot;&lt;/option&gt;&#092;n  &quot;;

This compares the value assigned to $categoryID when you did the error checking and compares it to the current option value. If they match, it inserts the selected=&quot;selected&quot; attribute, which displays the last selection made with the drop-down box. 

</description>
		<content:encoded><![CDATA[<p>@Martin</p>
<p>I don&#8217;t know if any of your code got stripped out. WordPress has a tendency to do that.  I don&#8217;t see the HTML option code in the sample code that you submitted. </p>
<p>If you want to retrieve the selected value from the select box used in ther example, use the following PHP code on the page that the form gets submitted to.  This will retrieve the selected value from categoryID and plug it into a variable named $categoryID. This assumes that you are using the POST method. </p>
<p>if (isset($_POST['categoryID'])) $categoryID = $_POST['categoryID'];</p>
<p>If you are trying to retain the selected value from the drop-down and display that if the form fails the error checking, then you need to change the code for line with the the option tag. Split the line with the option code into three lines.</p>
<p>  echo &#8220;&lt;option value=&#92;&#8221;".$row['category_id'].&#8221;&#92;&#8221;";<br />
  if ($categoryID == $row['category_id']) echo &#8221; selected=\&#8221;selected\&#8221;";<br />
  echo &#8220;&gt;&#8221;.$row['category_name'].&#8221;&lt;/option&gt;&#92;n  &#8220;;</p>
<p>This compares the value assigned to $categoryID when you did the error checking and compares it to the current option value. If they match, it inserts the selected=&#8221;selected&#8221; attribute, which displays the last selection made with the drop-down box.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

