Jump to content


Photo

Show new table each "Categorie" *SOLVED*


  • Please log in to reply
2 replies to this topic

#1 bergjes

bergjes
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 01 October 2006 - 07:02 PM

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.basketbal...lubprogramma.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>";

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 01 October 2006 - 08:11 PM

Just needs a slight modification
<?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>";
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 bergjes

bergjes
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 01 October 2006 - 08:43 PM

:)Thanks Barand!!!!!

It's just what I wanted. Super!!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users