Forum Moderators: coopster

Message Too Old, No Replies

Hello, new to PHP coding, trying to load data from MySQL in combo box

         

andybr22

3:00 pm on Mar 22, 2005 (gmt 0)

10+ Year Member



I am trying to grab the data from a data table in MySQL and and add a column to the selectable values of a combo box. From there I will grab that value selected stored in a variable and run a query for more data.

I just can't seem to figure out how to load the data into the combo box. Any help would be appriciated.

dreamcatcher

3:07 pm on Mar 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld andybr22. :)

A while loop should do the trick. Do you have a unique id number for each field? If so, something like this:


$query = mysql_query("SELECT data FROM table") or die(mysql_error());

echo "<select name=\"select\">\n";

while ($row = mysql_fetch_assoc($query))
{
echo "<option value=\"".$row['id']."\">$row['fieldname']</option>\n";
}

echo "</select>\n";

Then when you process your form:

$select = $_POST['select'];

$query2 = mysql_query("SELECT FROM table WHERE id = '$select' LIMIT 1") or die(mysql_error());

//display data

Hope that helps.

dc

andybr22

6:39 pm on Mar 22, 2005 (gmt 0)

10+ Year Member



Thank you. I know it was an easy question but again I am JUST starting out and that REALLY helped! Thank you again, and thank you for the welcome to the boards! :)

andybr22

7:22 pm on Mar 22, 2005 (gmt 0)

10+ Year Member



Thank you. I know it was an easy question but again I am JUST starting out and that REALLY helped! Thank you again, and thank you for the welcome to the boards! :)

dreamcatcher

12:57 am on Mar 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad I could help. If you still have problems, please post again and we will do our best to help you.

dc