Jump to content

Shop error (num rows...)


rootKID
 Share

Recommended Posts

I would do something like this, because isset will "work" on an empty string, which is what $_GET['cat_id'] would be if there was nothing in it.

if(empty($_GET['cat_id')){  $result = mysql_query ('SELECT * FROM `shop_cat` ORDER BY shop_cat_id ASC LIMIT 1')or die(mysql_error());  $row = mysql_fetch_assoc ($result);  $catID = $row['shop_cat_id'];}else{  $catID = $_GET['cat_id'];};$query = "SELECT * FROM shop_items WHERE FK_catID = ".$catID;

Edited by thescientist
Link to comment
Share on other sites

hey again tst... i just tried your code... but still wont work... errors again...

Link to comment
Share on other sites

i just can't think how to fix... tell me... and for real... do you think i should re-make the shop?...

Link to comment
Share on other sites

i just tried your code... but still wont work... errors again...
print out the query to see how does it look.
Link to comment
Share on other sites

you have to show us what you tried and what the outcome was. Again, basic debugging should be your first line of defense. What are you trying to confirm that values are what you expect them? How are you confirming that the code is not working? Which part? At what point? It's important that you start figuring out how to test and debug simple things like this.

Link to comment
Share on other sites

as useally, sorry... but sick...anyways tst... here is my shop.php code:

<?phpecho begin_box("Shop Categories");include ("shop_undermenu.php");echo end_box(); echo "<br />"; echo begin_box("Shop");$catID = $_GET['cat_id'];if(!isset($catID)){$result = mysql_query ('SELECT * FROM `shop_cat` ORDER BY shop_cat_id ASC LIMIT 1')or die(mysql_error());;$row = mysql_fetch_assoc ($result);$catID = $row['shop_cat_id'];}$query = "SELECT * FROM shop_items WHERE FK_catID = ".$catID;/*echo "<pre>";print_r($query);echo "</pre>";*/$result = mysql_query($query)or die(mysql_error());if(mysql_num_rows($result)>0)//Checking to see if there is any rows to take...{echo "<form action='' method='post'>";echo "<table class='shop_table_100'>";echo "<tr class='shop_tr_holder_css'>";echo "<td>Add</td>";echo "<td>Amount</td>";echo "<td>Product Name</td>";echo "<td>Price</td>";echo "<td>More Info</td>";echo "</tr>";while ($row = mysql_fetch_assoc($result)){echo "<tr>\n";echo "<td><input type='checkbox' name='check_addbox[".$row['item_id']."]' /></td>\n"; ////extra array...echo "<td><input type='text' name='amount[".$row['item_id']."]' size='1' value='1' /></td>\n"; //With extra array...echo "<td>".$row['item_name']."</td>\n";echo "<td>".$row['item_price']." USD</td>\n";echo "<td><a href='details.php'>Info</a></td>\n";echo "</tr>\n";}echo "</table>";echo "<form action='' method='post'>";echo "<table class='shop_table_100'";echo "<tr>";echo "<td><input type='submit' name='add_item' id='submit' class='shop_add_submit_button' value='Update Cart' /></td>";echo "</tr>";echo "</table>";echo "</form>";}//Ending IF (Num_Rows...)else{echo "<form action='' method='post'>";echo "<table class='shop_table_100'>";echo "<tr class='shop_tr_holder_css'>";echo "<td>ERROR!</td>";echo "</tr>";echo "</table>";echo "</form>";echo "<form action='' method='post'>";echo "<table class='shop_table_100'>";echo "<tr>";echo "<td>There are no Products added yet.</td>";echo "</tr>";echo "</table>";echo "</form>";}  if(isset($_POST['add_item'])){if(!empty($_POST['check_addbox'])){  foreach($_POST['check_addbox'] as $p_id => $check)  {   $amount = $_POST['amount'][$p_id]; //Getting the Amount from the box...   $_SESSION['cart'][$p_id] += $amount; //adding them to the session...   header("location: shop.php");  }}}echo end_box();?>

what i was trying here was just to add your code, (integrade it...)...and then hoped that it would work, but it did not... and then i added where i could i find it was needed, a mysql error php tag so i hoped that could show me somfthing more related...that did not help either... so im clueless right now... look at picture to see what it shows me... PS: Code for categories below...

<?php$under_query = "SELECT * FROM shop_cat";$under_result = mysql_query($under_query)or die(mysql_error()); if(mysql_num_rows($under_result)>0)//Checking to see if there is any rows to take...{while($u_row = mysql_fetch_assoc($under_result)){echo "<a href='shop.php?cat_id=".$u_row['shop_cat_id']."'>".$u_row['shop_cat_name']."</a> ";}}//If ends...else {echo "No categories to show... come back again later ...";}?>

Edited by rootKID
Link to comment
Share on other sites

well, the whole point was to trace the steps of your code. Figure out if you are getting a value of $_GET['cat_id'], see what the query in full looks like. I don't see you have provided or confirmed any of that. It sounds like your query is wrong because of some logic. Again, debug, debug, debug. I don't know my example didn't work, because you didn't tell me the errors. The point is that if a value wasn't provided in $_GET, you should get it from the database. isset is not sufficient because a member in $_GET (in this context) with no value will be an empty string "". I would try to follow my examples, and debug every step of the way and provide your findings. Don't assume anything. If you try something and it doesn't work, show us what you tried, with debugging, and tell us what the errors are.

Edited by thescientist
Link to comment
Share on other sites

hmm... ok, i will try and return soon with what ive finded... i will also ask my friends next week in the schools if they know how to fix... maybe my teacher, so see ya later :)... Regards; rootKID :).

Link to comment
Share on other sites

hello again tst... ive not asked my teacher yet, but will tomorrow... ive been sick lately, so had to stay home today... so i will send feedback tomorrow :).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...