0

对不起,这个相对新手的问题。在过去的一个小时里,我一直试图弄清楚为什么当我循环遍历名为 $propname 的数组时不想打印它。下面是我的代码

$result = mysql_query("SELECT * FROM `player_info` WHERE `position` = 'THP'") or die(mysql_error()) ;

while($row = mysql_fetch_array($result)) //create arrays
{   
    $id[] = $row['player_id'];      
    $propName[] = $row['name'];
    $propLastName[]= $row['surname'];
}//end while

 //create variables for looping
$x = sizeof($propName);
$index = 0;

while($index < $x) //print variables
{
    echo $propName[$index];
    $index ++;
}
4

2 回答 2

0
$result = mysql_query("SELECT * FROM `player_info` WHERE `position` = 'THP'") or             die(mysql_error()) ;

while($row = mysql_fetch_assoc($result)) //create arrays
{   
    $id = $row['player_id'];      
    echo $propName = $row['name'];
    $propLastName = $row['surname'];
}
于 2013-09-28T03:29:28.287 回答
0

只需简化您的代码

$result = mysql_query("SELECT * FROM `player_info` WHERE `position` = 'THP'") or die(mysql_error()) ;

while($row = mysql_fetch_array($result)) //create arrays
{   
    echo $row['name'];
}
于 2013-09-28T02:07:12.477 回答