bergjes Posted October 1, 2006 Share Posted October 1, 2006 Hi,I'm totaly new with PhP, so I don't know if this is an easy thing to accomplish.I have to display data from my MySQL database on my website.I have a script that does that, but the scipt put all the data in one large table.What I want is that it puts data of the same "categorie" in separate tables.An example of how I want it eventually you can found on http://www.basketball.nl/rayon/west/db/wedstrijd/clubprogramma.pl(Choose a Club and for "Hele seizoen")The code I have is like this:<?$username="";$password="";$database="joomla";mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query="SELECT * FROM qrycao";$result=mysql_query($query);$num=mysql_numrows($result);mysql_close();echo "<b><left>Tabel CAO lonen per 1 juli 2006</center></b><br><br>";?><table width="100%" border="1" cellspacing="2" cellpadding="2"> <tr bgcolor="#FF9900"> <th scope="col">Functieklasse</th> <th scope="col">Leeftijd</th> <th scope="col">Functiejaren</th> <th scope="col">Uurloon</th> <th scope="col">p/week</th> <th scope="col">p/4 weken </th> <th scope="col">p/maand</th> </tr><?$i=0;while ($i < $num) {$functieklasse=mysql_result($result,$i,"functieklasse");$leeftijd=mysql_result($result,$i,"leeftijd");$functiejaren=mysql_result($result,$i,"functiejaren");$loon_uur=mysql_result($result,$i,"loon_uur");$week=mysql_result($result,$i,"week");$weken=mysql_result($result,$i,"weken");$maand=mysql_result($result,$i,"maand");?> <tr> <td><? echo $functieklasse; ?> </td> <td><? echo $leeftijd; ?> </td> <td><? echo $functiejaren; ?> </td> <td><? echo $loon_uur; ?> </td> <td><? echo $week; ?> </td> <td><? echo $weken; ?> </td> <td><? echo $maand; ?> </td> </tr><?$i++;}echo "</table>"; Quote Link to comment Share on other sites More sharing options...
Barand Posted October 1, 2006 Share Posted October 1, 2006 Just needs a slight modification[code]<?php$i=0;$prevKlasse='';while ($i < $num) {$functieklasse=mysql_result($result,$i,"functieklasse");$leeftijd=mysql_result($result,$i,"leeftijd");$functiejaren=mysql_result($result,$i,"functiejaren");$loon_uur=mysql_result($result,$i,"loon_uur");$week=mysql_result($result,$i,"week");$weken=mysql_result($result,$i,"weken");$maand=mysql_result($result,$i,"maand");if ($functieklasse != $prevKlasse) { if ($prevKlasse != '') { echo '</table><br><br>'; // end current table } echo '<table>'; // start new table $prevKlasse = $functieklasse;}?> <tr> <td><? echo $functieklasse; ?> </td> <td><? echo $leeftijd; ?> </td> <td><? echo $functiejaren; ?> </td> <td><? echo $loon_uur; ?> </td> <td><? echo $week; ?> </td> <td><? echo $weken; ?> </td> <td><? echo $maand; ?> </td> </tr><?$i++;}echo "</table>";?>[/code] Quote Link to comment Share on other sites More sharing options...
bergjes Posted October 1, 2006 Author Share Posted October 1, 2006 :)Thanks Barand!!!!!It's just what I wanted. Super!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.