| 
	
 | 
 Posted by Jerry Stuckle on 06/24/06 03:06 
Jerry M. Gartner wrote: 
> Greetings: 
>  
>     As evident from a previous post, I am a php noob.  I would like to  
> display MySQL query results in an html table with one of the row values as a  
> category and the rest of the data displayed under the relevant category. 
>  
>     I can get as far as displaying the data in a nice readable format but I  
> don't know how to have the records placed under their corresponding  
> category.  This is my code thus far (sans the html output): 
>  
> ...ORDER BY cat ASC'; 
> while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
> printf("%s Class: %s  Description: %s", $row["cat"]$row["title"],  
> $row["desc"]); 
> } 
>  
>     As you can see, this only outputs each record with the selected rows but  
> we show multiple instances of the same category.  I know why this works the  
> way it does, I just don't know how to make it work the way I want.  Advice  
> is appreciated.  Thanks in advance. 
>  
>     Also, any good links for understanding and using arrays are welcome. 
 
Something like: 
 
$cat = ""; // Or any value you would never have for a category 
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
   if ($row['cat'] != $cat) { 
     echo $row['cat'] . ' '; 
     $cat = $row['cat']; 
   } 
   echo 'Class: ' . $row['title'] . "Description" . $row['desc']; 
} 
 
--  
================== 
Remove the "x" from my email address 
Jerry Stuckle 
JDS Computer Training Corp. 
jstucklex@attglobal.net 
==================
 
  
Navigation:
[Reply to this message] 
 |