I know this is possible to do but struggling to find the answer through Google  After selecting all rows from a table I need to show certain additional information from a single row.
Currently I'm selecting all rows from the table to populate a dropdown as below:
Code:
$wherestr = "";
$couriers = "SELECT * FROM couriers ".$wherestr." ORDER BY id";
$rs1 = mysql_query($couriers);
while($row = mysql_fetch_array($rs1))
{
// Print each courier as an option in the dropdown
echo "<option ";
if($result[0]['ship_courier']==$row['id']) echo "selected=\"selected\"";
echo "value=\"".$row['id']."\">".$row['name']."\n ";
}
?>
Works great. Depending on whichever courier has been chosen for the order I'm now needing to use that information to display the correct tracking URL (stored in a seperate column, same table):
Code:
$wherestr .= "where id=".$result[0]['ship_courier']."";
$couriers2 = $db->select($couriers);
// Grab the tracking URL
if ($result['0']['tracking_no']<>"") {
$track="<a target=\"_blank\" href=\"";
$track.=$couriers2[0]['tracking_url_1'].$result[0]['tracking_no'];
$track.="\">Track online</a>";
} else {
$track="Not Tracked";
}
echo $track;
The $wherestr is what I'm needing to add to the original Select query once it has initially run through to grab the names for my dropdown.
Currently it just grabs the first tracking URL found, and not the tracking URL of the selected courier. If I move my $wherestr to execute before the SELECT statement runs it successfully grabs the courier and correct URL, however it doesn't populate the remainder of the dropdown options.
Hope someone can put me out of my misery and tell me where I need to look 
|