Display client name only once

Hi!! I have a simple script of displaying client work history in following manner:

<?PHP
$query1=mysql_query
("SELECT 
existing_clients_work_history.history_description, 
existing_clients_work_history.history_history, 
client_master.client_name  
FROM 
existing_clients_work_history 
INNER JOIN 
client_master 
ON
existing_clients_work_history.client_id=client_master.client_id");
if(mysql_num_rows($query1) > 0)
{
echo "<table align='center' border='0' width='1000'>";
echo "<tr class='style1' align='center'>
<td>Client Name</td>
<td>Work Description</td>
<td>Work History</td>
</tr>";
while($row1=mysql_fetch_array($query1))
{
if($row1!=0)
{
echo "<tr>
<td class='style3'>"; echo $row1['client_name']; echo "</td>
<td class='style3'>"; echo $row1['history_description']; echo "</td>
<td class='style3'>"; echo $row1['history_history']; echo "</td>
</tr>";
}
}
echo "</table>";
}
else
{
echo "<div align='center' class='style1'>Sorry No Records Found..</div>";
}
?>

Problem is, there are multiple records belonging to same client.Is there any way out if I want to display client name only once & their records afterwards??

Sure, see this thread starting from post #3 :slight_smile:

That was very nice of you ScallioXTX.But I really messed up the code n nothing working f9. :frowning:

Yuhu!! This code worked atlast!! Thx a lot ScallioXTX!!

<?PHP $query_select = “SELECT
existing_clients_work_history.history_description,
existing_clients_work_history.history_history,
client_master.client_name
FROM
existing_clients_work_history
INNER JOIN
client_master
ON
existing_clients_work_history.client_id=client_master.client_id
ORDER BY existing_clients_work_history.client_id”;
$result_select = mysql_query($query_select) or die(mysql_error());
$rows = array();
while($row = mysql_fetch_array($result_select))
$rows = $row;
$lastName=‘’;

foreach($rows as $row)
{
$ename = stripslashes($row[‘client_name’]);
$eemail = stripcslashes($row[‘history_description’]);
$epost = stripslashes($row[‘history_history’]);
$eid = $row[‘client_id’];
if($ename != $lastName)
{ //if start
echo $ename . ‘<br/>’;
}//if end

echo $eemail . '&lt;br/&gt;';

echo $epost . '&lt;br/&gt;&lt;br/&gt;';
$lastName=$ename;

}
?>

Sorry I found a mistake in my code that I haven’t placed braces after my while loop.Its very odd thing that if I put opening & closing braces after while loop, I am not getting desired output.Is it OKEY if I keep the code as it is??

Your code is perfectly fine as it is now anita :tup:

What you have,


while($row = mysql_fetch_array($result_select))
$rows[] = $row;

is the same as


while($row = mysql_fetch_array($result_select))
{
  $rows[] = $row;
}

if you don’t use curly braces the body of a while (or for, foreach, etc) is the first line following it.
Works fine :slight_smile:

Didnt Know that!!