...

View Full Version : populate drop down from mysql with php part II



joviyach
06-25-2006, 03:23 AM
I have this working sort of, but I still can't figure out why it is skipping the "uniqid" field. Does it not work if the field is an auto_incrementing INT value or something?

Also, where do I add the "form action" elements to this code to allow the user to actually submit after selecting?



<?php

//connect to MySQL

$connect = mysql_connect("localhost","xxx","xxx") or
die ("Could not connect to database.");

//choose the database

mysql_select_db("peoplelist");

//get data from database

$query = mysql_query(
"SELECT `uniqid`,
`firstname`,
`lastname`
FROM `people`
ORDER BY `lastname` ASC"
) or die (mysql_error());

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

while ($data = mysql_fetch_array($query, MYSQL_ASSOC))
{
echo " <option value='{$data['uniqid']}'>{$data['lastname']},
{$data['firstname']}</option>\n";
}

echo "</select>\n";

?>

chump2877
06-25-2006, 06:07 AM
I have this working sort of, but I still can't figure out why it is skipping the "uniqid" field. Does it not work if the field is an auto_incrementing INT value or something?

Also, where do I add the "form action" elements to this code to allow the user to actually submit after selecting?

didnt test this or anything but see if it works better for you:



echo "<form name='form1' method='post' action='script.php'>\n";

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

while ($data = mysql_fetch_assoc($query))
{
echo "<option value='".$data['uniqid']."'>".$data['lastname'].",".$data['firstname']."</option>\n";
}

echo "</select>\n";

echo "<input type='submit' name='submit' value='Submit'>\n";

echo "</form>\n";

joviyach
06-25-2006, 06:29 PM
That worked great!

One more problem to solve then I am good to go I think. Most of this stuff can all be recycled and used over and over thoughout the application once it actually works correctly, but I still can't figure out why the crop down completely ignores the "uniqid" when populating from the database...

joviyach
06-30-2006, 01:49 AM
I think I know what is wrong with this, but I don't know the syntax of how to fix it. I have to comvert the uniqid value from an INT to CHAR or VARCHAR so it will work. Any suggestions?

Thanks,

Jim



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum