PDA

View Full Version : function ShowCart() query not displaying on page!!


tux
10-06-2009, 06:04 AM
Hello all,

I am trying to build a shopping cart and am having problems getting the ShowCart() function to display its content.

I can echo from the query in the PHP at the top of the page where the function is delacared but cant get the info to echo in the cart.

Here is my ShowCart() function....

function ShowCart(){

$result5 = @mysql_query("SELECT * FROM cart WHERE cartID = '12'");
$cart = @mysql_fetch_array($result5);

echo $cart['imageID']; //proves the query works.

// Increment the total cost of all items
$totalCost += ($cart["qty"] * $cart["productPrice"]);
}

and this is part of the cart.....

<?php do { ?>
<tbody>
<tr>
<td class="td2">
<img src="Images/Gallery/Thumbs/<?php echo $cart['imageID']; ?>" alt="<?php echo $cart['title']; ?>" title="<?php echo $cart['title']; ?>" />
</td>
<td class="td3">
<?php echo $cart['cartID']; ?>, <?php echo $cart['cookieID']; ?>
</td>
<td class="td4">
Processing
</td>
<td class="td5">
<select name="<?php echo $cart['productID']; ?>" onchange="UpdateQty(this)">
<?php for($i = 1; $i <= 20; $i++){
echo "<option";
if($cart['qty'] == $i){
echo "SELECTED";
}
echo ">" .$i. "</option>";
}
?>
</select>
</td>
<td class="td6"><?php echo $cart['cartID']; ?></td>
</tr>
</tbody>
<?php }while ($cart = mysql_fetch_array($result5)) ?>

I get this error on the page....

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\wamp\www\PaulTuckerPhotography\cart.php on line 204

Thanks for any help, Paul.

bee80
10-06-2009, 03:25 PM
is this line 204? :

<?php }while ($cart = mysql_fetch_array($result5)) ?>


try:

<?php }while ($cart = @mysql_fetch_array($result5)) ?>


also i think you need to return $cart so you can work with it outside the function:


function ShowCart(){

$result5 = @mysql_query("SELECT * FROM cart WHERE cartID = '12'");
$cart = @mysql_fetch_array($result5);

echo $cart['imageID']; //proves the query works.
return $cart;

// Increment the total cost of all items
$totalCost += ($cart["qty"] * $cart["productPrice"]);

}