DarkPrince2005 Posted July 24, 2008 Share Posted July 24, 2008 I'm busy with a shopping cart script, but the cart.php shows every singel item added. eg. if i add item a to the cart twice, it shows two itm a's each as a different entry. i've figured out the correct mysql_query to summarize the cart table but my browser keeps returning an error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource. <?php if (!session_id()) { session_start(); }//connect to the database $connect = mysql_connect("localhost", "root", "") or die ("Hey loser, check your server connection."); mysql_select_db("pc_lan_it"); ?> <html> <head> <title>Here is Your Shopping Cart!</title> </head> <body> <div align="center"> You currently have <?php $sessid = session_id(); //display number of products in cart $query = mysql_query("select product_id, sum(cart_qty), cart_session_id,cart_id from tbl_cart group by product_id where cart_session_id = '$sessid'"); $results = $query; //$rows = mysql_num_rows($results); echo $rows; ?> product(s) in your cart.<br> <table border="1" align="center" cellpadding="5"> <tr> <td>Quantity</td> <td>Item Image</td> <td>Item Name</td> <td>Price Each</td> <td>Extended Price</td> <td></td> <td></td> <?php //$total = 0; while ($row = mysql_fetch_array($results)) { echo "<tr>"; echo "<td> <form method=\"POST\" action=\"modcart.php?action=change\"> <input type=\"text\" name=\"modified_hidden\" value=\"$row[cart_id]\"> <input type=\"text\" name=\"modified_quan\" size=\"2\" value=\"$row[cart_qty]\">"; echo "</td>"; echo "<td>"; echo "$row[product_id]"; echo "</td>"; echo "<td>"; echo "<a href=\"getprod.php?prodid=" . $products_prodnum . "\">"; echo "$row[product_name]"; echo "</a></td>"; echo "<td align=\"right\">"; echo "$row[product_price]"; echo "</td>"; echo "<td align=\"right\">"; //get extended price $extprice = number_format($row['product_price'] * $row['cart_qty'], 2); echo $extprice; echo "</td>"; echo "<td>"; echo "<input type=\"submit\" name=\"Submit\" value=\"Change Qty\"> </form></td>"; echo "<td>"; echo "<form method=\"POST\" action=\"modcart.php?action=delete\"> <input type=\"hidden\" name=\"modified_hidden\" value=\"$row[cart_id]\">"; echo "<input type=\"submit\" name=\"Submit\" value=\"Delete Item\"> </form></td>"; echo "</tr>"; //add extended price to total $total = mysql_query("select sum(product_price) from tbl_cart where cart_session_id like '$sessid'"); } ?> <tr> <td colspan=\"4\" align=\"right\"> Your total before shipping is:</td> <td align=\"right\"> <?php echo number_format($total, 2); ?></td> <td></td> <td> <?php echo "<form method=\"POST\" action=\"modcart.php?action=empty\"> <input type=\"hidden\" name=\"carttemp_hidden\" value=\""; if (isset($carttemp_hidden)) { echo $carttemp_hidden; } echo "\">"; echo "<input type=\"submit\" name=\"Submit\" value=\"Empty Cart\"> </form>"; ?> </td> </tr> </table> <form method="POST" action="checkout.php"> <input type="submit" name="Submit" value="Proceed to Checkout"> </form> <a href="cbashop.php">Go back to the main page</a> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/116392-solved-displaying-a-result/ Share on other sites More sharing options...
samshel Posted July 24, 2008 Share Posted July 24, 2008 when in query doubt use mysql_error() $query = mysql_query("select product_id, sum(cart_qty), cart_session_id,cart_id from tbl_cart group by product_id where cart_session_id = '$sessid'") or die (mysql_error()); Link to comment https://forums.phpfreaks.com/topic/116392-solved-displaying-a-result/#findComment-598505 Share on other sites More sharing options...
DarkPrince2005 Posted July 24, 2008 Author Share Posted July 24, 2008 it seems to have a problem with where cart_session_id = '$sessid' Link to comment https://forums.phpfreaks.com/topic/116392-solved-displaying-a-result/#findComment-598512 Share on other sites More sharing options...
samshel Posted July 24, 2008 Share Posted July 24, 2008 group by product_id where cart_session_id = '$sessid'" switch group by and where clause should be where cart_session_id = '$sessid' group by product_id" Link to comment https://forums.phpfreaks.com/topic/116392-solved-displaying-a-result/#findComment-598515 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.