homepage Welcome to WebmasterWorld Guest from 54.205.247.203
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
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
reffik024




msg:3939859
 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

 

reffik024




msg:3939863
 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']},
{$data['FIRST_NAME']}</option>\n";
}

echo "</select>\n";

?>

reffik024




msg:3939973
 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";
else
echo "{$id}";
?>
<?
$query="SELECT * FROM patients WHERE id='$id'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();

$i=0;
while ($i < $num) {
$first=mysql_result($result,$i,"FIRST_NAME");
$last=mysql_result($result,$i,"LAST_NAME");
$address=mysql_result($result,$i,"ADDRESS");
$city=mysql_result($result,$i,"CITY");
$phone=mysql_result($result,$i,"PHONE");
$email=mysql_result($result,$i,"EMAIL");
$caid=mysql_result($result,$i,"CA_ID");

++$i;
}

clkdesign




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

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

<?php
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.

clkdesign




msg:3940014
 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.

reffik024




msg:3940405
 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