I am trying to exclude the an 'ID' from the Mysql_query but it is still returning the mentioned ID. This ID is '21' but the query returns '21' which is not what I wanted. Did I misspell something in the Mysql?
("SELECT * FROM `gallery` WHERE `gallery_id` NOT IN ('$notgallery')") or die (mysql_error());
function not_gallery($pic){
$pic = $_GET['id'];
$id = explode(".", $pic);
$notgallery = $id;
$notg = mysql_query("SELECT * FROM `gallery` WHERE `gallery_id` NOT IN ('$notgallery')") or die (mysql_error());
while($not_row = mysql_fetch_assoc($notg)){
$notgimage[] = array(
'id' => $not_row['gallery_id'],
'user' => $not_row['user_id'],
'name' => $not_row['name'],
'timestamp' => $not_row['timestamp'],
'ext' => $not_row['ext'],
'caption' => $not_row['caption'],
);
}
print_r($notgimage);
}
I print_r'ed the query and it is still returning '21' which I have excluded/or which I thought I did
Array ( [0] => Array ( [id] => 21 [user] => 18 [name] => NotDeojeff [timestamp] => 1367219713 [ext] => jpg [caption] => asd ) [1] => Array ( [id] => 22 [user] => 18 [name] => NotDeojeff [timestamp] => 1367225648 [ext] => jpg [caption] => Ogre magi )
There are a couple of problems. Take a look here:
"SELECT * FROM `gallery` WHERE `gallery_id` NOT IN ('$notgallery')"
$notgallery
is currently an array of IDs to check. You need to join them back together with implode
, like this:
$notgallery = implode(', ', $id);
Also, you have wrapped gallery_id
's NOT IN value in quotes. So in fact you'd get something like:
"SELECT * FROM `gallery` WHERE `gallery_id` NOT IN ('21, 13')"
Which is like saying WHERE gallery_id != '21, 13'
. Presuming you're using INT
s for the id
column, you need to remove the single quotes around $notgallery
. If you are using a string, you can alter your implode:
$notgallery = implode("', '", $id);
$notgallery is an array and in your SQL query you must have a list of id separated by a comma, so try:
$pic = $_GET['id'];
$id = explode(".", $pic);
$notgallery = $id;
$notgallery = implode(",", $notgallery);
$notg = mysql_query("SELECT * FROM `gallery` WHERE `gallery_id` NOT IN ($notgallery)") or die (mysql_error());
has above post n better way to put it.
$pic = $_GET['id'];
$id = explode(".", $pic);
$notgallery = $id;
$notgallery = implode(",", $notgallery);
$notg = mysql_query("SELECT * FROM `gallery` WHERE `gallery_id` NOT IN ($notgallery)") or die (mysql_error());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With