Skip navigation links

MySQL Forums :: PHP :: Assistance With PHP MySQL Query


Advanced Search

Assistance With PHP MySQL Query
Posted by: Mary Mills ()
Date: November 06, 2009 05:32PM

Hello-

I am relatively new to PHP and MySQL and would appreciate any assistance with a problem I am having.

This is the code I am using:
<?php
$con = mysql_connect("localhost","UID","PASSWORD");
if (!$con)
{die('Could not connect: ' . mysql_error());}
mysql_select_db("DBNAME", $con);

$query = "SELECT fname, lname, car_id, make FROM names LEFT JOIN cars on (names.name_id = cars.name_id) ORDER BY lname";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "{$row['fname']} {$row['lname']} <br>";
echo "{$row['car_id']} <br>";
echo "{$row['make']} <br>";
}
?>


Here is my output:

FirstName LastName1
1
Volkswagon

FirstName LastName2
2
Toyota

FirstName Lastname2
3
Mercury

FirstName LastName2
4
Lexus

I would like the output to be:

FirstName LastName1
1
Volkswagon

FirstName LastName2
2
Toyota

3
Mercury

FirstName LastName2
4
Lexus

I would like people who have multiple cars to only have the name print once and the cars print underneath.

Thank you very much for your time.

Options: ReplyQuote


Subject Written By Posted
Assistance With PHP MySQL Query Mary Mills 11/06/2009 05:32PM
Resolved - Assistance With PHP MySQL Query Mary Mills 11/06/2009 05:44PM


Sorry, only registered users may post in this forum.