Need help on this..

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

Need help on this..

Post by pookie62 »

Hi all,
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 "&nbsp;<a href="$PHP_SELF?page=$prevs&q=$var"><<
Vorige 20</a>&nbsp&nbsp;";
}

// 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 "&nbsp;<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);
?>

?>
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Re: Need help on this..

Post by xisle »

pookie62 wrote: <select name="select" size="1">
I think this is your name menu. First give it a more unique name like 'last_name'.

Then in your mysql select query add WHERE name = '.$_POST['last_name'].'
pookie62
Forum Commoner
Posts: 92
Joined: Tue Dec 07, 2004 2:44 pm

Post by pookie62 »

Hi xisle,
Let me first thank you for replying !
I changed the name to this:

Code: Select all

<?php
<select name="matchname" size="5">
?>
But now I get a parse error:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Inetpub\wwwroot\ASN\ASN\wedstrijduitslagtest2.php on line 29
Line 29 is the Query :

"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`)
WHERE 'wedstrijd`.`Naam`='.$_POST['matchname'].'
ORDER BY `wedstrijd`.`Naam`, `klasse`.`Klasse`, `Tijd`";

Where is the mistype ??
Thanks for your help..
Post Reply