php - How to print multiple ID's from a $_GET variable using while() and array() -


i'm here today because i'm under minor issue can't seem solve , it's why brings here. issue i'm trying multiple id's $_get variable print out. tried use array , great, works thing makes separate arrays [0] , need 1 in same array not array() array() doing.

so i'm using while() mysql_fetch_array results off database , depends on $_get url in-order grab correct id's. in url pass in api.php?do=remove&id=1,4,7 print out first id , not others name. said tried array() , came out :

array ( [0] => bzlxo.jpg ) array ( [0] => chztk.jpg ) array ( [0] => 9yset.jpg ) array ( [0] => ss04v.jpg ) 

i don't understand why doing need in 1 array in

array ( [0] => bzlxo.jpg, [1] => chztk.jpg, [2] => 9yset.jpg, [3] => ss04v.jpg ) 

so way when implode them show text in: "you removed image(s) "bzlxo.jpg,chztk.jpg,9yset.jpg,ss04v.jpg" like

 $iname[imagename] = array($iname[imagename]); $name = implode(",", $iname[imagename]); 

here code:

this url "api.php?do=remove&id=1,4,7"

 $id = $_get['id']; $query = "select id,imagename uploads id in ({$id}) , username = '{$uploader}'"; $result = mysql_query($query); while( $iname = mysql_fetch_array($result)){ $querys = "delete uploads id in ({$id}) , username = '{$uploader}'"; $results = mysql_query($querys); if(!$results) { $api_message = 'failed removal result'; } else { $iname[imagename] = array($iname[imagename]); $name = implode(",", $iname[imagename]); $api_message = "you removed image(s) $name"; } } 

the output :

you removed image(s) bzlxo.jpg

but need be:

the output : removed image(s) "bzlxo.jpg,chztk.jpg,9yset.jpg,ss04v.jpg"

any appreciated, if more information needed please let me know , i'll include

in addition solution posted raina77ow, there problem control flow in executing delete uploads id in (...) statement each iteration of while loop. delete records on first iteration. need change like:

$id = $_get['id']; $names = array(); $query = "select id,imagename uploads id in ({$id}) , username = '{$uploader}'"; $result = mysql_query($query); while( $iname = mysql_fetch_array($result)){ $querys = "delete uploads id = {$iname['id']} , username = '{$uploader}'"; $results = mysql_query($querys); if(!$results) { $api_message = 'failed removal result'; } else { $names[] = $iname['imagename']); } } $name = implode(",", $names); $api_message = "you removed image(s) $name"; 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -