Jump to content

Shop error (num rows...)


rootKID

Recommended Posts

Hello W3S... im having this error: (LOOK AT ATTACHED PICTURE...) and here is my shop.php code:

include ("shop_undermenu.php");$catID = $_GET['cat_id'];if(!isset($catID)){$result = mysql_query ('SELECT * FROM `shop_cat` ORDER BY shop_cat_id ASC LIMIT 1');$row = mysql_fetch_assoc ($result);$catID = $row['shop_cat_id'];}$query = "SELECT * FROM shop_items WHERE FK_catID = ".$catID;$result = mysql_query($query); if(mysql_num_rows($result)>0){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']."</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");  }}}

and that runs ok... the problem is in the shop_undermenu.php file i think... Code:

<?php$under_query = "SELECT * FROM shop_cat";$under_result = mysql_query($under_query)or die(mysql_error());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> ";}?>

ideas on how to fix would be greate :)... and note that im telling it to go to the First Category automaticly... but why its giving that error in the picture i dont know... i mean... i tried for fun to delete all of the SQL tables i had about the cat... (with a backup ofcourse...) but what i wish is that if there is no categories... but still products... and the products does not appear... then i wish just to show the error messeage that i was trying to like in the picture... ideas would be awsome... thanks W3S... Regards: rootKID -> Further information (in Details) can be given if this is not enough :)...

Edited by rootKID
Link to comment
Share on other sites

Is shop_cat_id an numeric or a text? Also, what's on line 63?

Link to comment
Share on other sites

Is shop_cat_id an numeric or a text? Also, what's on line 63?
Shop.php Line -> 63
if(mysql_num_rows($result)>0)

and the pictures added is the (shop_items),(shop_cat) tables i have...that should answer the question i suppose :)...

Link to comment
Share on other sites

Your error is inside that big if statement starting on line 63. Empty it and confirm that you don't get the same error. Then start adding back lines until you find the problem. If you can't fix it let us know. EDIT:Use exit; to avoid misleading errors.

Edited by niche
Link to comment
Share on other sites

I use

or die(mysql_error());

Edited by niche
Link to comment
Share on other sites

ok... will try.... thanks :)... posting feedback if can't fix :).. EDIT: jSG... you said i had a error in the SQL... but what error exacly... cannot see it :S...

Edited by rootKID
Link to comment
Share on other sites

rootKID, justsomeguy is right. The error said it was expecting a resource. The successful output from your query generates a sql resource so its absence says the query failed.

Link to comment
Share on other sites

but where... i mean... what do i need to fix? :/... just can't see it :/...

Link to comment
Share on other sites

Change

if(mysql_num_rows($result)>0)

to

mysql_num_rows($result);exit;

and add code from post six to the end of your query. Then report back.

Edited by niche
Link to comment
Share on other sites

do i need to remove the Whole If/Else word?... i mean... just the if/else and not stuff from inside...?

Link to comment
Share on other sites

still the same as in the picture i have added in post #7...

Link to comment
Share on other sites

That's good. Did you add

or die(mysql_error());

to the end of your queries?

Link to comment
Share on other sites

If I read correctly, this is the query that's supposed to have an error:SELECT * FROM shop_items WHERE FK_catID = ".$catID Print out the value of that and see what it looks like.

Link to comment
Share on other sites

yes i have done the mysql query error checking in all the query's now... on both files :)...

Link to comment
Share on other sites

Ingolme... you was right... somfthing is wrong with that query... picture added...

Link to comment
Share on other sites

ti does not gets a ID... and still trying to get the ID... i know that part... just not what to write to fix... :/... EDIT: ok... i think i might have fixed the shop_undermenu.php file... (the one that shows the categories...) with the very same tag (if)...CODE:

<?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 ...";}?>

the only problem im getting this now: (LOOK AT ATTACH IMAGE...) and no clue what to do now... hoping answers soon.. thanks :)...(will go to bed now... hoping a answer by morning... elsewhere i am really clueless right now...) :/... PS: Here are the Shop.php Code... just in case... lol :)... CODE:

include ("shop_undermenu.php");$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']."</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");  }}}

Edited by rootKID
Link to comment
Share on other sites

$_GET to blank?... would that not just give an another error?...and what do you mean with the cat table to be empty?... it allready is empty... and giving no errors due to the fix i just did... the only thing that im needing to fix is the shop.php now... :/... EDIT: orr is it me that does not understand what's being told...?...

Edited by rootKID
Link to comment
Share on other sites

first thing is you need to make sure you are even getting a value for $_GET['cat_id'] when the link.

var_dump($_GET);$catID = $_GET['cat_id'];

you wouldn't get an error because when the GET/POST are passed, they are converted to strings, so a blank value would just become an empty string, '' and also by verifying that there is even a value when you output it in the HTML

 $under_query = "SELECT * FROM shop_cat";$under_result = mysql_query($under_query)or die(mysql_error());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> ";}

make sure when you view the source of your page, that there is even a value being assign by $u_row['shop_cat_id'] the shop_cat table needs to have records in it in the first place right? Or else how would see any links? The loop wouldn't run in that situation. This is basic debugging. You need to trace all steps of your code, and know what each part is doing at all times.

Link to comment
Share on other sites

i do know what each part does... just that sometimes i kinda forget when its getting to the higher places like this... i mean... alot of codes in one place :)... but thanks... i will try and then post feedback if i succes... but just one more question... do i need to use the variable $catID that was created instead of the $u_row?... i mean... would it be the same... its both the same id... and giving less query's... right?... EDIT: going to bed... but giving feedback tomorrow... thanks for now :)...

Edited by rootKID
Link to comment
Share on other sites

hello again, hoping you still see this... i have now fixed the under-menu problem... but what i realize now is that its never been the category problem... but the shop... when a product does not gets a ID, then error.... but what i do not understand is that i have setted it into a (IF/ELSE) php word, so it should not give a error... shop.php Code below:

$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");  }}}

Category code below, then you also have that part...:

 $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 added yet...";}

but the code are about the shop.php...how can i fix it?... (Look at attachment if so...)

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
×
×
  • Create New...