I have a wordpress site with a scoreboard that gets results from a view in the wp database and I ve set up the board on a custom page template.My trouble is to link the players in the scoreboard to a new page with players stats etc. I want to be able to click the player name in the scoreboard and then get to a page with stats for that player.
Here is the relevant code that displays the scoreboard:
<?php //Table with SQL Query
$connection = mysql_connect('localhost', 'root', '');
mysql_set_charset('utf8',$connection);
mysql_select_db('worldsbestblog');
$query = "SELECT * FROM Sammenlagt LIMIT 0,20";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){ //Loop through results
echo "<tr><td>" . $row['Dato'] . "</td>
<td>
<a href=\"fasan.php?id=". $row["spillerid"]."\">" . $row['Navn'] . "</a>
</td>
<td>" . $row['hull1'] . "</td><td>" . $row['hull2'] .
"</td><td>" . $row['hull3'] . "</td><td>" . $row['hull4'] .
"</td><td>" . $row['hull5'] . "</td><td>" . $row['hull6'] .
"</td><td>" . $row['hull7'] . "</td><td>" . $row['hull8'] .
"</td><td>" . $row['hull9'] . "</td><td>" . $row['hull10'] .
"</td><td>" . $row['hull11'] . "</td><td>" . $row['hull12'] .
"</td><td>" . $row['hull13'] . "</td><td>" . $row['hull14'] .
"</td><td>" . $row['hull15'] . "</td><td>" . $row['hull16'] .
"</td><td>" . $row['hull17'] . "</td><td>" . $row['hull18'] .
"</td><td>" . $row['Sammenlagt'] . "</td><td>" . $row['Par'] .
"</td><td>" . $row['Poeng'] . "</td></tr>"; //$row['index'] the index here is a column name
}
?>
I've seen countless similar questions where SESSIONS, $_POST and $_GET has been used though I havent been able to either understand or see how/if thats what's missing in order to make it work. As it is now i get a URL showing the userid of player, but when clicked, wordpress cant find that page.
[edit]
OK I have done some editing and found an answer to my question. Unsure how to go about here on stackoverflow (direct me if I should do this elsewhere), but I want to show you what did the job so that the next guy will find this post with an explanation.
So here is the current code and thanks to @Cal Evans and @Hamed Momeni for helpful guidance:
Scoreboard goes:
$query = "SELECT * FROM Sammenlagt";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){ //Creates a loop to loop through results
echo "<tr><td>" . $row['Dato'] . "</td>
<td>
<a href=\"/wordpress/teststats?id=". $row["spillerid"]."\">" . $row['Navn'] . "</a>
</td>
<td>" . $row['hull1'] . "</td><td>" . $row['hull2'] .
"</td><td>" . $row['hull3'] . "</td><td>" . $row['hull4'] .
"</td><td>" . $row['hull5'] . "</td><td>" . $row['hull6'] .
"</td><td>" . $row['hull7'] . "</td><td>" . $row['hull8'] .
"</td><td>" . $row['hull9'] . "</td><td>" . $row['hull10'] .
"</td><td>" . $row['hull11'] . "</td><td>" . $row['hull12'] .
"</td><td>" . $row['hull13'] . "</td><td>" . $row['hull14'] .
"</td><td>" . $row['hull15'] . "</td><td>" . $row['hull16'] .
"</td><td>" . $row['hull17'] . "</td><td>" . $row['hull18'] .
"</td><td>" . $row['Sammenlagt'] . "</td><td>" . $row['Par'] .
"</td><td>" . $row['Poeng'] . "</td></tr>"; //$row['index'] the index here is a column name
}
?>
.../wordpress/teststats
is a new page with a custom page template with the following code:
<?php
$spid = (int) filter_input(INPUT_GET,'id', FILTER_SANITIZE_NUMBER_INT);
$spillerquery = mysql_query("SELECT * FROM Sammenlagt WHERE spillerid='$spid'") or die ("Somthing went wrong!!");
if (mysql_num_rows($spillerquery) < 1){
die ("Couldnt find that player");
}
$navnequery = mysql_query("SELECT Navn FROM Sammenlagt WHERE spillerid='$spid'") or die ("Player does not exist");
$spillernavn = mysql_result($navnequery,MYSQL_BOTH);
?>
<h2>Her er <?php echo "$spillernavn"; ?> sine resultater</h2>
<?php
while($row = mysql_fetch_array($spillerquery, MYSQL_ASSOC)){
echo "<tr><td>" . $row['Dato'] .
"</td><td>" . $row['hull1'] . "</td><td>" . $row['hull2'] .
"</td><td>" . $row['hull3'] . "</td><td>" . $row['hull4'] .
"</td><td>" . $row['hull5'] . "</td><td>" . $row['hull6'] .
"</td><td>" . $row['hull7'] . "</td><td>" . $row['hull8'] .
"</td><td>" . $row['hull9'] . "</td><td>" . $row['hull10'] .
"</td><td>" . $row['hull11'] . "</td><td>" . $row['hull12'] .
"</td><td>" . $row['hull13'] . "</td><td>" . $row['hull14'] .
"</td><td>" . $row['hull15'] . "</td><td>" . $row['hull16'] .
"</td><td>" . $row['hull17'] . "</td><td>" . $row['hull18'] .
"</td><td>" . $row['Sammenlagt'] . "</td><td>" . $row['Par'] .
"</td><td>" . $row['Poeng'] . "</td></tr>";
}
?>