我试图将所有trackName从mysql中拉出来。在mysql中运行脚本时,它可以很好地工作。此外,如果我将。$ info ['trackName']更改为“示例Trank”也可以正常工作
所以我的问题是为什么不打印从数据库中提取的曲目?
以下是我正在使用的代码:
<?php
$data = mysql_query(" SELECT li.leagueID, li.seasonID , li.championshipID, li.userID , li.trackID, tr.trackName
FROM leagueinformation li
INNER JOIN tracks tr ON tr.trackID = li.trackID
WHERE leagueID = 1 AND seasonID = 1 AND championshipID = 1 AND userID = 1 ") or die(mysql_error());
$trackNumber = 1;
while($info = mysql_fetch_array( $data )) {
echo "<div class=\"span2\">\n";
echo " <h5> Track " . $trackNumber . " :" . "</h5><span>" . $info['tr.trackName'] . "</span>\n";
echo " </div>\n";
$trackNumber++;
}
?>
答案 0 :(得分:0)
看起来像语法错误,但我找不到它, 你应该使用$ info变量中的var_dump()函数来获得这样的数组键的确切语法。
抱歉,我有一个问题,我不能通过所有代码只是把var_dump($ info);在你循环 希望它有用问候
答案 1 :(得分:0)
尝试这样的事情:
$query = "SELECT
li.leagueID,
li.seasonID ,
li.championshipID,
li.userID ,
li.trackID,
tr.trackName
FROM
li
INNER JOIN
tr
ON
tr.trackID = li.trackID
WHERE
li.leagueID = 1 AND
li.seasonID = 1 AND
li.championshipID = 1 AND
li.userID = 1 ";
$data = mysql_query($query) or die(mysql_error());
if(mysql_num_rows($data) < 1){
die("No rows found");
}
$trackNumber = 1;
while($info = mysql_fetch_assoc($data)){
echo "<div class=\"span2\">\n";
echo " <h5> Track " . $trackNumber . " : </h5><span>" . $info['trackName'] . "</span>\n";
echo " </div>\n";
$trackNumber++;
}