【发布时间】:2016-10-28 18:51:48
【问题描述】:
我正在从 JSON 链接解析 3 个变量,每个变量都包含电影院的名称:
$cinema1
$cinema2
$cinema3
之后,我需要从表中选择所有 3 个电影院的 id,然后使用该 id 查找表“movietimings”以查看今天是否有电影正在播放,是否有电影正在播放今天电影院,然后我需要去“电影”表并显示有关该电影的所有信息。
所以,这就是已经完成的:
$sql2 = "SELECT DISTINCT * FROM cinema WHERE cinemaname = '$cinema1' AND cinemaname='$cinema2' AND cinemaname='$cinema3' ";
$result2 = $conn->query($sql2);
if ($result2->num_rows > 0) {
// output data of each row
while($row2 = $result2->fetch_assoc()) {
$cinemaid2 = $row2['id'];// I have received a cinema id
//getting the main id, since the id I just got is a branch of the main cinema, so the main id that is associated with movie timings is down below
$sql5 = "SELECT DISTINCT * FROM cinemas WHERE cinemaname = '$cinemaid2'";
$result5 = $conn->query($sql5);
if ($result5->num_rows > 0) {
// output data of each row
while($row5 = $result5->fetch_assoc()) {
$cinemaid = $row5['id'];//received main id required
$today = date("m/d/Y");//getting todays date
//now trying to find if a movie today playing
$sql3 = "SELECT * FROM moviecinemashowsassociation WHERE cinemaid LIKE '$cinemaid' AND showdate LIKE '$today'";
$result3 = $conn->query($sql3);
if ($result3->num_rows > 0) {
// output data of each row
while($row3 = $result3->fetch_assoc()) {
$movieid = $row3['movieid'];// selected a movie id played today
//selecting information about movie
$sql4 = "SELECT * FROM movie WHERE id='$movieid'";
$result4 = $conn->query($sql4);
if ($result4->num_rows > 0) {
// output data of each row
while($row4 = $result4->fetch_assoc()) {
问题是我有 3 个不同的电影院,它们应该经过一个循环。
【问题讨论】:
-
请为我们定义:“不工作”。变量的值是...? db架构是什么? db 中的值是什么?
-
你需要学习布尔逻辑。您是在说“电影名称字段必须同时是以下所有三个值”。你想要一个
or。 "可以是以下任意值" -
感谢您的回复。我正在更改问题,因为我似乎没有清楚地理解问题。
-
Little Bobby 说 your script is at risk for SQL Injection Attacks.。即使escaping the string 也不安全! SQL 注入!。 不再只是早餐!
-
我已经更新了问题,任何帮助将不胜感激。