Table layout

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pookie62
Forum Commoner
Posts: 92
Joined: Tue Dec 07, 2004 2:44 pm

Table layout

Post by pookie62 »

Hi,
I want to display a table in a specific way.
Matchnames(Wedstrijdnaam) as toprow
Firstname + Lastname in second column
Perc in crosscell
Like:
"Empty Cell" | Match1 | Match2 | Match3
Firstname+Lastname | Perc (for this match) | Perc | -- (when there's no score for this match

Here's the script I use now, this displays everything vertically.
Thanks in advance !

Code: Select all

<?php
 require_once('../../Connections/ASN.php'); ?>
<?php
error_reporting(E_ALL); 
mysql_select_db($database_ASN, $ASN);
    
    $query="SELECT `wedstrijd`.`Naam` AS `Wedstrijd`,`klasse`.`Klasse`,`overzicht`.`Voornaam` AS `Voornaam`,`deelnemer`.`Naam` AS `Achternaam` , `overzicht`.`Percentage` AS `Perc` FROM `overzicht` INNER JOIN `deelnemer` ON (`overzicht`.`DeelnemerId` = `deelnemer`.`Id`) INNER JOIN `wedstrijd` ON (`overzicht`.`WedstrijdId` = `wedstrijd`.`Id`) INNER JOIN `klasse` ON (`overzicht`.`KlasseId` = `klasse`.`Id`) WHERE (`klasseID` = 1)";
    $result = mysql_query ($query)
        or die ("Query failed");

    // printing HTML result

    print "<table>\n";
    $cnt = 0;
    while ($line = mysql_fetch_assoc($result)):
        print "\t<tr>\n";
        if ($cnt === 0):
            foreach ($line  as $key=>$val):
                echo "<td>$key</td>";
            endforeach;
            echo "</tr><tr>";
            $cnt++;
        endif;        
        foreach ($line as $val):
            print "\t\t<td>$val</td>\n";
        endforeach;
        print "\t</tr>\n";
    endwhile;
    print "</table>\n";
?>
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

And what exactly is your problem ??
pookie62
Forum Commoner
Posts: 92
Joined: Tue Dec 07, 2004 2:44 pm

Post by pookie62 »

Oke, let me try again..
Data in this table is growing as more matches are finished in time.
Each match has it's own name and ID
Competitors want to see all their results (Perc) for every match they competed in.
Something like this:


Empty Cell | Matchname A | Matchname B | Next match when data is uploaded
Name of competitor | 0.80% | 0.52% | Result for this match


How do I code this ???
pookie62
Forum Commoner
Posts: 92
Joined: Tue Dec 07, 2004 2:44 pm

Post by pookie62 »

Tried this code but still the names are on a new row, I want them besides eacother (one row)
Driving me crazy..

Code: Select all

$Match="SELECT DISTINCT `wedstrijd`.`Naam` AS `Wedstrijd` FROM `overzicht` LEFT OUTER JOIN `wedstrijd` ON (`overzicht`.`WedstrijdId` = `wedstrijd`.`Id`)";
$res = mysql_query ($Match)
        or die ("Match Query failed");
		while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
$wnaam= $row['Wedstrijd'];
$wnames = array ($wnaam);

print '<html><body><table border=1>';

$table_width = 30;
$table_counter = 0;
foreach ($wnames as $theelement)
{
    if ($table_counter == 0)
    {
        print '<tr><td';
    }
    
    print '<td>' . $theelement . '</td>';
    
    $table_counter++;
    
    if ($table_counter == $table_width)
    {
        print '</td>';
        $table_counter = 0;
    }
}

for ($counter = 0; $counter < $table_width - $table_counter; $counter++)
{
    //print '<td> </td>';
}

print '</table></body></html>';
}
?>
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post by matthijs »

a small typo on line:

Code: Select all

print '<tr><td';
Missing >
Does that make a difference?
Also, were does the table row end (the </tr>)? Shouldn't that also be in the end of the loop?
Post Reply