PHP: Mysql ("SELECT WHERE ID NOT ") -
i trying exclude 'id' mysql_query still returning mentioned id. id '21' query returns '21' not wanted. did misspell in mysql?
("select * `gallery` `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 * `gallery` `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 query , still returning '21' have excluded/or thought 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 couple of problems. take here:
"select * `gallery` `gallery_id` not in ('$notgallery')"
$notgallery
array of ids check. need join them implode
, this:
$notgallery = implode(', ', $id);
also, have wrapped gallery_id
's not in value in quotes. in fact you'd like:
"select * `gallery` `gallery_id` not in ('21, 13')"
which saying where gallery_id != '21, 13'
. presuming you're using int
s id
column, need remove single quotes around $notgallery
. if using string, can alter implode:
$notgallery = implode("', '", $id);
Comments
Post a Comment