...

View Full Version : Dynamically creating a select control.



Darth Sensei
03-27-2007, 09:51 PM
I have the basics of PHP fairly well and I have RTFM, but I simply cannot figure out what I'm doing wrong with this. I know it's prolly simple.

Can any of you gurus please point out the error of my ways?


$query = "Select RecID, ColCode, ColName, endcaps from colors WHERE endcaps = '1'";

$result = mysql_query($query);
//echo (mysql_num_rows($result));
while ($row = mysql_fetch_array($result)){
echo "<option value = \"{$row[1]}\">{$row[1]}</option>"

It throws parsing errors on the last line. I know I have a good result with 4 rows. The $row[1] has 3 digit numbers in it like 208, 209, etc.

I want the statement generated to be:
<option value="208">208</option>

Can anyone tell me what the hell I'm doing wrong?

Nightfire
03-27-2007, 09:59 PM
$query = "Select RecID, ColCode, ColName, endcaps from colors WHERE endcaps = '1'";

$result = mysql_query($query);
//echo (mysql_num_rows($result));
while ($row = mysql_fetch_array($result)){
echo "<option value = \"{$row[1]}\">{$row[1]}</option>";
}

It's also easier if you do it this way


$query = "Select RecID, ColCode, ColName, endcaps from colors WHERE endcaps = '1'";

$result = mysql_query($query);
//echo (mysql_num_rows($result));
while ($row = mysql_fetch_array($result)){
echo '<option value="'.$row[1].'">'.$row[1].'</option>';
}

Darth Sensei
03-27-2007, 10:01 PM
Thanks for the fast reply. :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum