Reputation: 11
Hi I have the details of two car drivers getting pulled from a database but then I want to just grab one of the two and echo it out in php. I am able to take both drivers details and echo them both out using a while loop but not target just one of them:
By using the code below I echo out both records. Is there a way to just grab one of them?
while($row = mysql_fetch_array($result))
{
echo "A driver:<br />";
echo "Name:". $row['FirstName'] . " " . $row['LastName']."<br />";
echo "Latitude:". $row['CoordLat']."<br />";
echo "Longitude:". $row['CoordLong'];
$driverlat = $row['CoordLat'];
$driverlong = $row['CoordLong'];
}//end of while loop
Upvotes: 1
Views: 37
Reputation: 6208
You don't need a while loop at all.
Just do $row = mysql_fetch_array($result);
on it's own separate line.
This will display the first row result.
Upvotes: 1
Reputation: 23041
Just remove the while
loop ?
$row = mysql_fetch_array($result))
echo "A driver:<br />";
echo "Name:". $row['FirstName'] . " " . $row['LastName']."<br />";
echo "Latitude:". $row['CoordLat']."<br />";
echo "Longitude:". $row['CoordLong'];
$driverlat = $row['CoordLat'];
$driverlong = $row['CoordLong'];
Upvotes: 1
Reputation: 29739
You can just put a break;
at the end of the while loop. Then only the first row is processed.
Better way would be to use no loop: Just assign the $row
and do the render stuff.
Upvotes: 0