Forum Moderators: coopster
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
$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";
?>
$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;
}
<?php
while ($row = mysql_fetch_assoc($query)) { // begins loop
$first = $row['first_name'];
$last = $row['last_name'];
print "$firstname $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.