html - PHP Invalid argument supplied for foreach() loop -
i trying make sure every column in database pull html first 2 columns pull. last 3 columns don't work. 2 text values , last column decimal. can please tell me missing? thank you!
$colmname = $_post["colname"]; $colmvalue = $_post["colvalue"]; $count = 0; if ($colmname = 'productid') { $thequery = "select * products productid = $colmvalue"; $rset = $db->query ($thequery); } elseif ($colmname = 'categoryid') { $thequery = "select * products categoryid = $colmvalue"; $rset = $db->query($thequery); } elseif ($colmname = 'productcode') { $thequery = "select * products (productcode = '$colmvalue')"; $rset= $db->query($thequery); } elseif ($colname = 'productname') { $thequery = "select * products (productname = '$colmvalue')"; $rset = $db->query ($thequery); } elseif ($colname = 'listprice') { $thequer = "select * products listprice = $colmvalue"; $rset = $db->query ($thequery); } else { echo ('enter valid column name products table , existing value. either productid, categoryid, productcode, productname, or listprice.'); include (index.html); exit (); }//end if foreach($rset $products) { $list .= $count.' '.$products['productid'] .' '.$products['categoryid'] .' '.$products['productcode'] .' '.$products['productname'] .' '.$products['listprice'] .'<br>'; $count++; }//foreach echo ("<p>the data $colmname value of $colmvalue listed below:<p>"); // echo ($list);//just check if works before putting in table // echo ('<p>');//for spacing ?> <doctype! html> <html> <head> <title>product results</title> </head> <body> <section> <table border="1"> <tr><th>productid</th><th>categoryid</th><th>productcode</th><th>productname</th><th>listprice</th></tr> <tr><td><?php echo $products['productid'];?></td><td><?php echo $products['categoryid'];?></td><td><?php echo $products['productcode'];$ </table> </section> </body> </html>
so long $db->query
regular mysql_query() function, cannot use foreach. should use:
while ($products = mysql_fetch_assoc($rset)) { $list .= $count.' '.$products['productid'] .' '.$products['categoryid'] .' '.$products['productcode'] .' '.$products['productname'] .' '.$products['listprice'] .'<br>'; $count++; }
Comments
Post a Comment