I am trying to display the contents of a shopping cart using ShowCart() (see below)

The

echo $result;

gives Resource id #4 as the output.

What does Resource id #4 mean?
Any ideas why the cart is not displaying?

Thanks.

function ShowCart()
	{
		// Gets each item from the cart table and display them in
		// a tabulated format, as well as a final total for the cart

	global $dbServer, $dbUser, $dbPass, $dbName;

	// Get a connection to the database
	$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName) or die(mysql_error());

	$totalCost = 0;
	$result = mysql_query("select * from cart inner join items on cart.ITEMID = items.ITEMID where cart.cookieId = '" . GetCartId() . "' order by items.ITEMNAME asc") or die(mysql_error());

//look at result
echo $result;

    mysql_query() returns a resource handle to the query in mysql. To get the actual data you have to recieve it line by line with mysql_fetch statement. I personally like to use
    $row=mysql_fetch_array($result);
    but there are also mysql_fetch_row(), mysql_fetch_object() just to name a couple.
    Have a look on php.net to find which best meets your requirements.

    One would normally place this statement in a loop of some sorts to get each row as it comes.
    for example

    <?php
    while($row=mysql_fetch_array($res)) {
      //deal with each row as it comes
    }
    ?>

    HTH & Good Luck
    Bubble

      $result is not the array of items from the query, it is the handle for the resources used to create the query.

      you should complete the php code to add all the items into an array of some kind and then return that array back to your page to go thru and show

        Write a Reply...