homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Populate Dropdown List and Link
how to populate dropdown list from mysql and redirect based off selection

 10:16 pm on Jun 24, 2009 (gmt 0)

I have found similar posts, but having some trouble still. I'm trying to populate a dropdown list from a dropdown list and have that redirect to a page where the profile of that selection can be updated (this is for patient records).

The name of the two fields I need to call are FIRST_NAME and LAST_NAME, to be ordered like "Last Name, First Name" in the dropdown. Then that page should redirect. I know this is pretty basic--i'm new :D



 10:28 pm on Jun 24, 2009 (gmt 0)

OK I got the first part of it working, but how do I make the selection redirect to a dynamic link?

$query = mysql_query("SELECT `ID`,`FIRST_NAME`,`LAST_NAME`FROM `patients`ORDER BY `LAST_NAME` ASC")
or die (mysql_error());

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

while ($data = mysql_fetch_array($query, MYSQL_ASSOC))
echo " <option value='{$data['ID']}'>{$data['LAST_NAME']},

echo "</select>\n";



 1:37 am on Jun 25, 2009 (gmt 0)

ok, here's what i've got so far but i'm receiving an error:

$id = $_POST['id'];
if (empty($id))
echo "fail";
echo "{$id}";
$query="SELECT * FROM patients WHERE id='$id'";

while ($i < $num) {



 3:41 am on Jun 25, 2009 (gmt 0)

$query="SELECT * FROM patients WHERE id='$id'";
//puts the results in an array
$result=mysql_query($query); or die(mysql_error());

while ($row = mysql_fetch_assoc($query)) { // begins loop

$first = $row['first_name'];
$last = $row['last_name'];

print "$firstname&nbsp;$lastname<br />";

You need to call your array name. When you retrieved the information from the database the results from the mysql_queary got put into an array, you need to call that information out of the array. What reffik024 posted is the same as what I posted the difference being a step was cut out by the way the information is displayed on the screen.

the while function is a loop so you don't need to do the ++$i thing, while does it for you automatically :) it will loop through and write all the information you put into the function until it gets to the end of the array that your getting the information from.


 3:43 am on Jun 25, 2009 (gmt 0)

err.. *smacks forehead*

never mind I thought someone else had posted a reply, okay, A dynamic link is what your after? sorry I got confused by the last post that was made.


 6:10 pm on Jun 25, 2009 (gmt 0)

Thanks clkdesign, actually figured it out. Rather than the whole dynamic link thing i'm just using the selection from the first page to pull information from the db on that ID tag on the second page. Thanks for your reply though!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved