私は、変数の各映画館の名で構成され、JSONのリンクから3つの変数を解析しています:php - sql select "where"はいくつかの変数に等しい?
$cinema1
$cinema2
$cinema3
私は、そのIDを使用して、テーブルからすべての3つの映画館の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()) {
問題は、私は1つのループを経る必要があり、3種類の映画館を持っているということです。
cinemaname
は時間の同じ時点で複数の値を保持することはできませんので、それは価値のいずれか
WHERE cinemaname = '$cinema1' OR cinemaname = '$cinema2' OR cinemaname = '$cinema3'
(OR)の使用を指定したことになるので、あなたが代わりにAND
条件のOR
条件を探している
定義:「動作していません」。変数の値は...ですか? dbスキーマは何ですか? dbの値は何ですか? –
ブール論理を学ぶ必要があります。あなたは、 "フィールドcinemanameは、次の3つの値のすべてでなければなりません"と言っています。あなたは 'または'が欲しい。 "次のいずれかの値を指定できます" –
返信いただきありがとうございます。 私は問題をはっきりと理解していなかったように思われるため、質問を変更しています。 –