2014-02-13 40 views
0

我不知道为什么,但我在这行收到错误:$row = mysql_fetch_array($run_games)){ 以下是代码:PHP MySQL的可能是语法错误

<div class='topnav'> <!--Start of the Top Navigation--> 
<?php 
include("includes/connect.php"); 

$select_games = "SELECT * FROM games"; 

$run_games = mysql_query($select_games); 

$row = mysql_fetch_array($run_games)){ 

$game_category = $row['game_category']; 

?> 

<!--some links here with the variable of "game_category"--> 
<?php } ?> 
</div> <!--End of the Top Navigation--> 

请帮我:(

+0

我会尽量解释更好的是,我创建了一个系统,将一个新游戏上传到我的网站,其中一个参数是“game_category”游戏已经上传了,它现在在MySQL中选择了“game_category”,例如:“action”(动作游戏)。所以现在,当它准备好时,我想显示该游戏的“动作游戏”页面,这是一个categories.php文件,根据其类别生成游戏结果...但我试图使用此导航栏链接结果...有什么建议么? – davidgpilot

+0

哈哈!我终于解决了这个问题,我在我的navbar.php中根本不需要任何php ...我已经在categories.php中使用了php脚本来通过game_category过滤我的结果,所以我只是在导航栏上的每个链接这个:'

  • the game category
  • '。 谢谢大家;) – davidgpilot

    +0

    请回答你自己的问题并接受它,所以它也可以帮助别人。 –

    回答

    0

    它应该是..

    while($row = mysql_fetch_array($run_games)) 
    { 
    echo $game_category = $row['game_category']; 
    } 
    

    您通过ResultSet需要循环!

    +0

    问题是,我不想使用while循环,我只想包括它一次... – davidgpilot

    +0

    您的查询会返回多个结果? –

    +0

    我只需要返回1个结果,并且它的'game_category'来自PHPMYADMIN – davidgpilot

    0

    遍历结果集使用

    $row = mysql_fetch_array($run_games)){ 
    

    应该

    while($row = mysql_fetch_array($run_games)) { 
        // do stuff ... 
    } 
    
    +0

    我一旦编辑了它,我就删除了我的评论。 –

    +0

    我一看到你就删除了我的回复。 –

    +0

    大声笑,我也看到了。似乎我们正在播放“评论”删除标记哈哈 –

    0

    这可能是一个剪切和粘贴错误。您while循环的第一部分丢失:

    $row = mysql_fetch_array($run_games)){ 
    

    应该

    while ($row = mysql_fetch_array($run_games)){ 
    
    0

    这些功能已被弃用,所以使用最新的文档

    $row = mysql_fetch_array($run_games));//if only one row 
    //other wise should use while 
    while($row = mysql_fetch_array($run_games)) 
    { 
    } 
    
    +0

    它的好,我已经解决了它,明天我会在这里发布我的答案;) – davidgpilot