0

Hi! i have problems one query.

$day_result has a value of 1 and 4

$sql3 = "Select * from Venue where idVenue != $day_result";
echo $sql3;
if i use for loop for the above it will give the result below

Select * from Venue where idVenue != 1
Select * from Venue where idVenue != 4

But this is the result i want to get:

Select * from Venue where idVenue != 1 and idVenue != 4

how can i do it?

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by genevish
0

Select * from Venue where idVenue != 1 and idVenue != 4


Your 1 and 4 is in different coloumn or same column?
If 1 and 4 is in same column then,it is wrong query... Becoz it is never possible.

other wise , you can use like that....
Select * from Venue where idVenue != 1 or idVenue != 4

0

If you want to use PHP to create a string containing a SELECT query containing both values in a $day_result array, you could do it like this:

<?php
$day_result = array(1, 4); // Initial array of numbers
$sql3 = "Select * from Venue where ";

foreach($day_result as $day_num){
    $dr[] = "idVenue != $day_num "; // Build array of strings
}

$sql3 .= implode(' AND ', $dr); // convert to string joined by ' AND ' and add to end of $sql3

echo $sql3;
?>

Edited by d5e5: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.