我发现了一些解决了相同类型错误的问题,但这些问题并没有真正解决我的问题。
我不是MySQL的专家,但我正试图进入下一个级别并制作电影时间表。
我正在尝试从MySQL数据库中检索结果,但它没有从PHP获得预期的结果,但它正在PHPMyAdmin上的SQL浏览器上检索正确的结果。
这是数据库结构:
flm_schedulechart
s_id m_id t_id room day time status
1 1 1 5 0 16:30:00 1
2 1 3 2 0 13:30:00 0
3 1 3 2 1 13:30:00 1
flm_movietheaters_profiles
t_id name
1 Theater 1
3 Theater 2
知道我是否在PHPMyAdmin的SQL浏览器中运行这个sql语句...
SELECT s.s_id as 'show_id', t.name as 'theater', s.room as 'room', s.day as 'day', s.time 'time', s.status
FROM flm_schedulechart AS s
JOIN flm_movietheaters_profiles AS t
ON s.t_id = t.t_id
WHERE s.m_id=1
ORDER BY t.name
它检索:
show_id theater room day time status
1 Theater 1 5 0 16:30:00 1
2 Theater 2 2 0 13:30:00 0
3 Theater 2 2 1 13:30:00 1
如果我使用这个PHP代码......
这些是我的PHP函数:
function getCurrentShowingsByMovieId($con, $movie_id) {
$result = mysqli_query( $con, "
SELECT s.s_id as 'show_id', t.name as 'theater', s.room as 'room', s.day as 'day', s.time 'time', s.status
FROM flm_schedulechart AS s
JOIN flm_movietheaters_profiles AS t
ON s.t_id = t.t_id
WHERE s.m_id=$movie_id
ORDER BY t.name" );
return $result;
}
if( isset($_GET['mid']) ) {
$r = getCurrentShowingsByMovieId( $con, $_GET['mid'] );
$r = mysqli_fetch_assoc( $r );
}
var_dump($r);
它只检索第一个结果:
array(6) {
["show_id"]=>
string(1) "1"
["theater"]=>
string(16) "Theater 1"
["room"]=>
string(1) "5"
["day"]=>
string(1) "0"
["time"]=>
string(8) "16:30:00"
["status"]=>
string(1) "1"
}
希望这很清楚:)
提前致谢!
答案 0 :(得分:0)
你必须循环结果:
if( isset($_GET['mid']) ) {
$r = getCurrentShowingsByMovieId( $con, $_GET['mid'] );
while($row = mysqli_fetch_assoc($r)) {
echo "<pre>" . print_r($row,1) . "</pre>";
}
}