June 19, 201016 yr Hi i have a script that i suposed to get a list of the items in my database with a cat id of 25 but it doesnt work.... here is the script <?php //connect to database $mysqli = mysqli_connect("host", "user", "pass", "db"); if (isset($_GET["cat_id"])) { //get items $get_items_sql = "SELECT id, item_title, item_price FROM store_items WHERE cat_id = '".$cat_id."' ORDER BY item_title"; $get_items_res = mysqli_query($mysqli, $get_items_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($get_items_res) < 1) { $display_cat = "<p><em> Sorry,There are no items in this category.</em></p>"; } else { $display_cat .= "<ul>"; while ($items = mysqli_fetch_array($get_items_res)) { $item_id = $items['id']; $item_title = stripslashes($items['item_title']); $item_price = $items['item_price']; $display_cat .= "<li><a href=\"showitem.php? item_id=".$item_id."\">".$item_title."</a>(\$".$item_price.")</li>"; } $display_cat .= "</ul>"; } } mysqli_close($mysqli); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php echo $display_cat; ?> </body> </html> Any help would be greatly apreciated
June 19, 201016 yr You haven't set the $cat_id variable when you use it in the first query... $cat_id = $_GET['cat_id']; Assuming you've said your database details correctly...
Create an account or sign in to comment