Page 1 of 1

Table layout

Posted: Thu Jan 19, 2006 2:14 am
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";
?>

Posted: Thu Jan 19, 2006 4:22 am
by timvw
And what exactly is your problem ??

Posted: Thu Jan 19, 2006 4:39 am
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 ???

Posted: Thu Jan 19, 2006 8:07 am
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>';
}
?>

Posted: Thu Jan 19, 2006 8:14 am
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?