表格行数据在网络上显示两次

时间:2021-07-04 15:23:24

I am creating an online baseball management game, i have xxampp installed on my local pc, and the code i have written so far displays as i like it on the localhost, however when i transfer these files to the webserver, it displays each row twice anyone have any idea why that would be?

我正在创建一个在线棒球管理游戏,我在我的本地电脑上安装了xxampp,到目前为止我编写的代码在localhost上显示为我喜欢它,但是当我将这些文件传输到网络服务器时,它会显示每行两次任何人都知道为什么会这样?

<?php
include("./Lib/Database.php");
$db = new Database(false);
$query_string = "SELECT * FROM player, team WHERE TeamID AND PlayerTeamID ='".$_SESSION['TEAMID']."'";

$db->Query($query_string);
$db->SelectNextResult();
while ($row = $db->SelectNextResult()) {
echo("<DIV class='ComponentMain' align='center'>");
echo("<DIV class='ComponentTitle'>Team Name</DIV>");
echo("<BR><TABLE align='center'>");
{
  echo("<TR bgcolor='#DDDDDD'><TD colspan='6'><A HREF='./Player.php?ID=".$db-   >GetResult("PlayerID")."'><DIV class='PlayerName'>".$db->GetResult("PlayerPrenameValue")." ".$db->GetResult("PlayerNameValue")."</DIV></A></TD><TD align='right'><IMG src='./Gfx/Flags/". $db->GetResult("PlayerNationID").".png'/></TD></TR>");
echo("<TR><TD>    Age:</TD><TD>".$db->GetResult("PlayerAge")."</TD><TD>Potential:</TD><TD>".$db->GetResult("Potential")."</TD><TD>Health:</TD><TD>".$db->GetResult("Health")."</TD></TR>");
echo("<TR><TD colspan='5' align='center'><IMG src='./Gfx/Faces/Face.png'/></TD>");
{
    echo("<TR><TD>Contact:</TD><TD>".$db->GetResult("Contact")."</TD><TD>Power:</TD><TD>".$db->GetResult("Power")."</TD><TD>Vision:</TD><TD>".$db->GetResult("Vision")."</TD></TR>");
    echo("<TR><TD>Fielding:</TD><TD>".$db->GetResult("Fielding")."</TD><TD>Intelligence:</TD><TD>".$db->GetResult("Intelligence")."</TD><TD>Speed:</TD><TD>".$db->GetResult("Speed")."</TD></TR>");
    echo("<TR><TD>Morale:</TD><TD>".$db->GetResult("Morale")."</TD><TD>Pitching Skill:</TD><TD>".$db->GetResult("Skills")."</TD><TD>Velocity:</TD><TD>".$db->GetResult("Velocity")."</TD></TR>");
}
echo("<TR><TD colspan='5' align='center'>------------------------------------</TD></TR>");

}
echo("</TABLE>");
echo("<BR></DIV>");
}
$db->Close();
?>

as far as the $db commands those are not the issue, i think it could be the while im really not sure as usually when i do this on other projects i have no issues, this is a larger project though and the first of its type i have attempted its just rather wierd, any advice would be appreciated, anothe wierd thing i noticed was that in amongst my files for this site i have a file that defines some elements for the webapp, and on xampp no issues, on webserver it requires me to close the opening php tag in the file to accept the class Site lol so i dunno maybe its the webserver ?

至于$ db命令那些不是问题,我认为它可能是我真的不确定通常当我在其他项目上这样做我没有问题,这是一个更大的项目虽然和它的第一个类型我试过它只是相当奇怪,任何建议都会受到赞赏,我注意到的另一个奇怪的事情是,在我的文件中,我有一个文件定义了webapp的一些元素,并且在xampp没有问题,在webserver上它需要我关闭文件中的开放php标签接受类网站大声笑所以我不知道也许它的网络服务器?

3 个解决方案

#1


2  

There are problems in your query (I've split it into multiple lines so it won't scroll off the page):

您的查询中存在问题(我将其拆分为多行,因此不会滚动页面):

$query_string = "SELECT * FROM player, team " .
  "WHERE TeamID AND PlayerTeamID = '" . $_SESSION['TEAMID'] . "'";

Here's what I see:

这是我看到的:

  • The WHERE TeamID will include any TeamID that isn't zero.

    WHERE TeamID将包含任何非零的TeamID。

  • You're joining tables player and team but you don't have a join condition. That means that if your database has two teams, each player will be doubled. If your database has three teams, each player will be tripled. And so on.

    您正在加入桌面玩家和团队,但您没有加入条件。这意味着如果您的数据库有两个团队,每个玩家将加倍。如果您的数据库有三个团队,则每个玩家将增加三倍。等等。

I'd be willing to bet that your local database has one team and the database you access from your web server has two teams. Your query should be something like this:

我愿意打赌你的本地数据库有一个团队,你从web服务器访问的数据库有两个团队。您的查询应该是这样的:

$query_string = "SELECT * FROM player, team " .
  "WHERE team.TeamID = player.PlayerTeamID " .
  "  AND player.PlayerTeamID = '" . $_SESSION['TEAMID'] . "'";

I've guessed at the second line above. Substitute the columns that are used to tie the tables together and you'll be fine.

我已经猜到了上面的第二行。替换用于将表绑在一起的列,你会没事的。

Or better yet, use ANSI joins because (a) they're the standard and (b) they make it plain what your join logic is. This query does exactly the same as the one above:

或者更好的是,使用ANSI连接,因为(a)它们是标准,(b)它们使连接逻辑变得清晰。此查询与上面的查询完全相同:

$query_string = "SELECT * FROM player " .
  "INNER JOIN team ON team.TeamID = player.PlayerTeamID " .
  "WHERE player.PlayerTeamID = '" . $_SESSION['TEAMID'] . "'";

You may also have issues with your PHP code, but if you fix the query first you'll find them soon enough.

您可能还有PHP代码问题,但如果您先修复查询,您很快就会找到它们。

Finally, a suggestion: use MySQL Workbench or the MySQL Command Line to test your queries before putting them into the PHP code. You'll save a lot of time.

最后,建议:使用MySQL Workbench或MySQL命令行测试您的查询,然后再将它们放入PHP代码中。你会节省很多时间。

#2


0  

It seems you have too many brackets.

看来你的括号太多了。

Place:

echo("<DIV class='ComponentMain' align='center'>");
echo("<DIV class='ComponentTitle'>Team Name</DIV>");
echo("<BR><TABLE align='center'>");

Before while() statement. The logic something like this:

在while()语句之前。逻辑是这样的:

<table>
<tr>
<?php while( $sql = $row ) { ?>
<tr>
   <td><?php echo $row->stuff; ?></td>
   <td><?php echo $row->stuff1; ?></td>>
</tr>
<?php } ?>
</tr>
</table>

Hope it work !

希望它有用!

#3


0  

try this code ,and what u see

尝试这个代码,你看到了什么

include("./Lib/Database.php");
$db = new Database(false);
$query_string = "SELECT * FROM player, team WHERE TeamID AND PlayerTeamID ='".$_SESSION['TEAMID']."'";
$db->Query($query_string);
while ($row = $db->SelectNextResult()) {
$row->PlayerID; // or $row['PlayerID'];  // or $db->GetResult("Contact")
}
$db->Close();

#1


2  

There are problems in your query (I've split it into multiple lines so it won't scroll off the page):

您的查询中存在问题(我将其拆分为多行,因此不会滚动页面):

$query_string = "SELECT * FROM player, team " .
  "WHERE TeamID AND PlayerTeamID = '" . $_SESSION['TEAMID'] . "'";

Here's what I see:

这是我看到的:

  • The WHERE TeamID will include any TeamID that isn't zero.

    WHERE TeamID将包含任何非零的TeamID。

  • You're joining tables player and team but you don't have a join condition. That means that if your database has two teams, each player will be doubled. If your database has three teams, each player will be tripled. And so on.

    您正在加入桌面玩家和团队,但您没有加入条件。这意味着如果您的数据库有两个团队,每个玩家将加倍。如果您的数据库有三个团队,则每个玩家将增加三倍。等等。

I'd be willing to bet that your local database has one team and the database you access from your web server has two teams. Your query should be something like this:

我愿意打赌你的本地数据库有一个团队,你从web服务器访问的数据库有两个团队。您的查询应该是这样的:

$query_string = "SELECT * FROM player, team " .
  "WHERE team.TeamID = player.PlayerTeamID " .
  "  AND player.PlayerTeamID = '" . $_SESSION['TEAMID'] . "'";

I've guessed at the second line above. Substitute the columns that are used to tie the tables together and you'll be fine.

我已经猜到了上面的第二行。替换用于将表绑在一起的列,你会没事的。

Or better yet, use ANSI joins because (a) they're the standard and (b) they make it plain what your join logic is. This query does exactly the same as the one above:

或者更好的是,使用ANSI连接,因为(a)它们是标准,(b)它们使连接逻辑变得清晰。此查询与上面的查询完全相同:

$query_string = "SELECT * FROM player " .
  "INNER JOIN team ON team.TeamID = player.PlayerTeamID " .
  "WHERE player.PlayerTeamID = '" . $_SESSION['TEAMID'] . "'";

You may also have issues with your PHP code, but if you fix the query first you'll find them soon enough.

您可能还有PHP代码问题,但如果您先修复查询,您很快就会找到它们。

Finally, a suggestion: use MySQL Workbench or the MySQL Command Line to test your queries before putting them into the PHP code. You'll save a lot of time.

最后,建议:使用MySQL Workbench或MySQL命令行测试您的查询,然后再将它们放入PHP代码中。你会节省很多时间。

#2


0  

It seems you have too many brackets.

看来你的括号太多了。

Place:

echo("<DIV class='ComponentMain' align='center'>");
echo("<DIV class='ComponentTitle'>Team Name</DIV>");
echo("<BR><TABLE align='center'>");

Before while() statement. The logic something like this:

在while()语句之前。逻辑是这样的:

<table>
<tr>
<?php while( $sql = $row ) { ?>
<tr>
   <td><?php echo $row->stuff; ?></td>
   <td><?php echo $row->stuff1; ?></td>>
</tr>
<?php } ?>
</tr>
</table>

Hope it work !

希望它有用!

#3


0  

try this code ,and what u see

尝试这个代码,你看到了什么

include("./Lib/Database.php");
$db = new Database(false);
$query_string = "SELECT * FROM player, team WHERE TeamID AND PlayerTeamID ='".$_SESSION['TEAMID']."'";
$db->Query($query_string);
while ($row = $db->SelectNextResult()) {
$row->PlayerID; // or $row['PlayerID'];  // or $db->GetResult("Contact")
}
$db->Close();