Using a set of Mysql results as a comparison in PHP -


this question quite simple i'm not sure of terms involved answer myself. have mysql database containing of product information. make image appear on product pages products have attribute. have created sql query outputs list of product_ids products image show on. however, not know how use set of results in page itself.

i have:

$cupwinnerids = mysql_query("select product_id `jos_vm_product_type_1` jos_vm_product_type_1.cup_winner ='cup winners';"); while($row = mysql_fetch_array($cupwinnerids))   {   echo $row['product_id'] . ",";   } 

this outputs correct ids comma in between them. wrap whole thing $listofids = (...) , can use in product page php file: if $product_id in $listofids ... if not ... having problem understanding how use selection of ids. if try output list directly "array". appreciated.

the problem may trying display array using echo, while should use print_r.

in case this:

$listofids = array(); $cupwinnerids = mysql_query("select product_id `jos_vm_product_type_1` jos_vm_product_type_1.cup_winner ='cup winners';"); while($row = mysql_fetch_array($cupwinnerids)) { array_push($listofids, $row['product_id']); } print_r($listofids); 

as ryan commented, if want manage values of array should use foreach loop, iterates through array, this

foreach ($listofids $id) { echo $id . ", "; } // edit: use echo implode($listofids,", ") same 

if want compare if $product_id in $listofids in_array, returns true if value looking in array, , false if isn't:

if (in_array($product_id, $listofids)) { echo "product id in list of product id's"; } else { echo "product id isn't in list of product id's"; } 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -