Welcome to WebmasterWorld Guest from 54.160.131.144

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Populate Dropdown List and Link

how to populate dropdown list from mysql and redirect based off selection

     

reffik024

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

5+ Year Member



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

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

5+ Year Member



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

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

5+ Year Member



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

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

5+ Year Member



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

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

5+ Year Member



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

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

5+ Year Member



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!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month