Newbie as I am, I can't get this piece of code display the way I would like to. I would like to select a name (matchname) form the table `wedstrijd`.
Accordingly to that selected name I want to display in a tabular way the results of this match.
The code I use now is displaying all matches results..
Can somebody please review (and probably) optimize this code ??
Thanks very much, it's driving me crazy...
Code: Select all
<?php
<?php require_once('../Connections/testsite.php');
mysql_select_db($database_testsite, $testsite);
$query_wedstrijd = "SELECT Naam FROM wedstrijd";
$wedstrijd = mysql_query($query_wedstrijd, $testsite) or die(mysql_error());
$row_wedstrijd = mysql_fetch_assoc($wedstrijd);
$totalRows_wedstrijd = mysql_num_rows($wedstrijd);
/* Printing results in HTML */
?>
<form name="form1" method="post" action="">
<h1>
<select name="select" size="1">
<?php
do {
?>
<option value="<?php echo $row_wedstrijd['Naam']?>"<?php if (!(strcmp($row_wedstrijd['Naam'], $row_wedstrijd['Naam']))) {echo "SELECTED";} ?>><?php echo $row_wedstrijd['Naam']?></option>
<?php
} while ($row_wedstrijd = mysql_fetch_assoc($wedstrijd));
$rows = mysql_num_rows($wedstrijd);
if($rows > 0) {
mysql_data_seek($wedstrijd, 0);
$row_wedstrijd = mysql_fetch_assoc($wedstrijd);
}
?>
</select>
</h1>
</form>
<p>
<?php
$query_Uitslag = "SELECT `klasse`.`Klasse`, `deelnemer`.`Naam` AS `Deelnemer`, `deelnemer`.`Vereniging` AS `Vereniging`,`deelnemer`.`URL` AS `URL`, `wedstrijd`.`Datum`, `wedstrijd`.`Plaats` AS `Plaats`, TRUNCATE (`score`.`Tijd`, 2) AS `Tijd` FROM `deelnemer` INNER JOIN `inschrijving` ON (`deelnemer`.`Id` = `inschrijving`.`DeelnemerId`) INNER JOIN `wedstrijd` ON (`inschrijving`.`WedstrijdId` = `wedstrijd`.`Id`) INNER JOIN `klasse` ON (`inschrijving`.`KlassId` = `klasse`.`Id`) INNER JOIN `score` ON (`inschrijving`.`Id` = `score`.`InschrijvingId`) ORDER BY `wedstrijd`.`Naam`, `klasse`.`Klasse`, `Tijd`";
$result = mysql_query($query_Uitslag, $testsite) or die(mysql_error());
$row_result = mysql_fetch_assoc($result);
$numrows = mysql_num_rows($result);
$limit = 20;
$query_count = ($query_Uitslag);
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
$totalpages = ceil($totalrows/$limit);
$page = (!empty($_REQUEST['page'])) ? $_REQUEST['page'] + 1 : 1;
$s = $page;
$limitvalue = $page * $limit - ($limit);
// Begin your table outside of the array
echo "<table width="65%" border="1" cellpadding="2" cellspacing="2">
<tr>
<td><b>Nr</b></td>
<td><b>Klasse</b></td>
<td><b>Naam</b></td>
<td><b>Vereniging</b></td>
<td><b>Wedstrijd</b></td>
<td><b>Tijd</b></td>
</tr>";
// Define your colors for the alternating rows
$color1 = "#ADD8E6";
$color2 = "#E0FFFF";
$row_count = 1;
/* Printing results in HTML */
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$row_count = $row_count;
$Klasse = $line["Klasse"];
$Naam = $line["Deelnemer"];
$Vereniging = $line["Vereniging"];
$Wedstrijd;
$Tijd = $line["Tijd"];
$URL = $line["URL"];
/* Now we do this small line which is basically going to tell
PHP to alternate the colors between the two colors we defined above. */
$row_color = ($row_count % 2) ? $color1 : $color2;
// Echo your table row and table data that you want to be looped over and over here.
echo "<tr>
<td width="5" bgcolor="$row_color">$row_count</td>
<td width="10" bgcolor="$row_color">$Klasse</td>
<td width="200" bgcolor="$row_color">$Naam</td>
<td width="160" bgcolor="$row_color" nowrap><a href="$URL">$Vereniging</td>
<td width="200" bgcolor="$row_color">$Wedstrijd</td>
<td width="80" bgcolor="$row_color" nowrap>$Tijd</td>
</tr>";
//<td width="160" bgcolor="$row_color" nowrap><a href="$URL">$Vereniging</td>
// Add 1 to the row count
$row_count++;
}
//break before paging
echo "<br />";
// next we need to do the links to other results
if ($s>1) { // bypass PREV link if s is 0
$prevs=($page-2);
print " <a href="$PHP_SELF?page=$prevs&q=$var"><<
Vorige 20</a>  ";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
// check to see if last page
if (((($s+$limit)-1)>=$pages) && $pages!=0) {
// not last page so give NEXT link
$news=$page;
echo " <a href="$PHP_SELF?page=$news&q=$var">Volgende 20 >></a>";
}
$a = $s * $limit;
if ($a > $totalrows) { $a = $totalrows; }
$b = $limit * $page - $limit + 1;
echo "<p>Results $b to $a of $totalrows</p>";
mysql_free_result($result);
/* Closing connection */
mysql_close($testsite);
?>
?>