Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-25-2006, 03:23 AM   PM User | #1
joviyach
New Coder

 
Join Date: Sep 2005
Location: Steger, IL
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
joviyach is an unknown quantity at this point
Question populate drop down from mysql with php part II

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 Code:
<?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($queryMYSQL_ASSOC))
{
    echo 
"    <option value='{$data['uniqid']}'>{$data['lastname']},
{$data['firstname']}</option>\n"
;
}

echo 
"</select>\n";

?>
__________________
Jim
joviyach is offline   Reply With Quote
Old 06-25-2006, 06:07 AM   PM User | #2
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,549
Thanks: 15
Thanked 131 Times in 124 Posts
chump2877 is on a distinguished road
Quote:
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:


PHP Code:
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"
__________________
Regards, R.J.

---------------------------------------------------------

Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
[Related videos and tutorials are also available at my YouTube channel]

Last edited by chump2877; 06-25-2006 at 06:10 AM..
chump2877 is offline   Reply With Quote
Old 06-25-2006, 06:29 PM   PM User | #3
joviyach
New Coder

 
Join Date: Sep 2005
Location: Steger, IL
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
joviyach is an unknown quantity at this point
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...
__________________
Jim
joviyach is offline   Reply With Quote
Old 06-30-2006, 01:49 AM   PM User | #4
joviyach
New Coder

 
Join Date: Sep 2005
Location: Steger, IL
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
joviyach is an unknown quantity at this point
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
__________________
Jim
joviyach is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:41 PM.


Advertisement
Log in to turn off these ads.