gpt4 book ai didi

PHP MySQL 记分牌,带有个人资料页面的链接

转载 作者:行者123 更新时间:2023-11-29 23:11:08 25 4
gpt4 key购买 nike

我有一个带有记分牌的 WordPress 网站,可以从 wp 数据库中的 View 获取结果,并且我已经在自定义页面模板上设置了记分板。我的麻烦是将记分牌中的玩家链接到包含玩家的新页面统计数据等。我希望能够单击记分牌中的球员姓名,然后进入包含该球员统计数据的页面。

以下是显示记分板的相关代码:

<?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
}
?>

我见过无数类似的问题,其中使用了 SESSIONS、$_POST 和 $_GET,尽管我无法理解或了解如何/是否缺少这些才能使其工作。现在我得到了一个显示玩家用户ID的URL,但是当点击时,wordpress无法找到该页面。

<小时/>

[编辑]
好的,我已经做了一些编辑并找到了我的问题的答案。不确定如何在 stackoverflow 上进行此操作(如果我应该在其他地方执行此操作,请指导我),但我想向您展示这项工作是做什么的,以便下一个人可以找到这篇带有解释的帖子。

这是当前的代码,感谢@Cal Evans 和@Hamed Momeni 的帮助指导:

记分牌显示:

$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 是一个带有自定义页面模板的新页面,代码如下:

<?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>";
}

?>

最佳答案

试试这个。

<?php 
//Table with SQL Query

$player_id = (int) filter_input(INPUT_GET,'id', FILTER_SANITIZE_NUMBER_INT);

$connection = mysql_connect('localhost', 'root', '');
mysql_set_charset('utf8',$connection);
mysql_select_db('worldsbestblog');

$query = "SELECT * FROM Sammenlagt where player_id = {$player_id} LIMIT 0,20";

$result = mysql_query($query);

尽管如此,我确实同意with @Hamed您应该使用 $wpdb 而不是创建自己的连接。这是假设您的表与 WordPress 表位于同一数据库中。

关于PHP MySQL 记分牌,带有个人资料页面的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28074961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com