Jump to content

Show new table each "Categorie" *SOLVED*


bergjes

Recommended Posts

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; ?>&nbsp;</td>
    <td><? echo $leeftijd; ?>&nbsp;</td>
    <td><? echo $functiejaren; ?>&nbsp;</td>
    <td><? echo $loon_uur; ?>&nbsp;</td>
    <td><? echo $week; ?>&nbsp;</td>
    <td><? echo $weken; ?>&nbsp;</td>
    <td><? echo $maand; ?>&nbsp;</td>
  </tr>

<?
$i++;
}

echo "</table>";
Link to comment
Share on other sites

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; ?>&nbsp;</td>
    <td><? echo $leeftijd; ?>&nbsp;</td>
    <td><? echo $functiejaren; ?>&nbsp;</td>
    <td><? echo $loon_uur; ?>&nbsp;</td>
    <td><? echo $week; ?>&nbsp;</td>
    <td><? echo $weken; ?>&nbsp;</td>
    <td><? echo $maand; ?>&nbsp;</td>
  </tr>

<?
$i++;
}

echo "</table>";
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.