-1

I am parsing 3 variables from JSON link, each of variable consist of the name of a cinema theater:

$cinema1
$cinema2
$cinema3

After, I need to select an ids of all 3 cinemas from the table, then using that ids I need to look for the table "movietimings" to see if there is movies are playing today, if there is a movie playing in that cinemas today, then I need to go for "movie" table and show all information about that movie.

So, this is what have been accomplished:

    $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()) {

The problem is that I have 3 different cinemas which should go through one loop.

J. Doe
  • 254
  • 1
  • 3
  • 13
  • define: "not working" for us please. Variables' values are...? db schema is what? values in db are what? – Funk Forty Niner Oct 28 '16 at 18:53
  • 1
    You need to learn boolean logic. You're saying "the field cinemaname must be, SIMULTANEOUSLY, all three of the following values". You want an `or`. "can be any of the following values" – Marc B Oct 28 '16 at 18:53
  • Thanks for the reply. I am changing the question cause it seems like I did not understood the problem clearly. – J. Doe Oct 28 '16 at 18:55
  • [Little Bobby](http://bobby-tables.com/) says ***[your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)***. Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! ***SQL Injection!***. *It's not just for breakfast any more!* – Jay Blanchard Oct 28 '16 at 18:58
  • I have updated the question, any help will be much appreciated. – J. Doe Oct 28 '16 at 19:07

1 Answers1

1

You are looking for a OR condition instead of AND condition since the cinemaname can't hold multiple value at same point of time and thus it would be either of the values specified

WHERE cinemaname = '$cinema1' OR cinemaname = '$cinema2' OR cinemaname = '$cinema3'

(OR) Use a IN operator

WHERE cinemaname IN ('$cinema1' ,'$cinema2' , '$cinema3')
Rahul
  • 76,197
  • 13
  • 71
  • 125
  • Thanks for an answer, I need to get a movie timings from all of the 3 cinemas. I have updated the question, would appreciate if you will have a look. – J. Doe Oct 28 '16 at 19:07
  • @J.Doe, not sure what you are trying to do but this condition `WHERE cinemaname = '$cinema1' AND cinemaname='$cinema2' AND cinemaname='$cinema3'` will always be `false` resulting your query to return 0 records. Change that to `OR` condition instead. – Rahul Oct 28 '16 at 19:12
  • Solved the problem!:) Thanks a lot Rahul – J. Doe Oct 28 '16 at 19:25