1

I have a PHP page that retrieves the arrays in my $_SESSION['products'] session. Each array in that session is a product added by the user to their "shopping cart" via the catalogue.php page. Currently my session has eleven arrays meaning I have added eleven products to the cart. I am now trying to display the arrays on my view_cart.php page, and paginate them by ten. Basically I would like the page to show the first ten arrays then to display the eleventh array on view_cart.php?Page=2. Right now, the code displays all eleven arrays on the page at once, and displays three error messages before each array. I have posted the errors below.

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 'OFFSET'. (severity 15) in D:\Hosting\4502990\html\partscatalogue\view_cart4.php on line 63

Warning: mssql_query() [function.mssql-query]: message: Invalid usage of the option NEXT in the FETCH statement. (severity 15) in D:\Hosting\4502990\html\partscatalogue\view_cart4.php on line 63

Warning: mssql_query() [function.mssql-query]: Query failed in D:\Hosting\4502990\html\partscatalogue\view_cart4.php on line 63

Warning: mssql_fetch_object(): supplied argument is not a valid MS SQL-result resource in D:\Hosting\4502990\html\partscatalogue\view_cart4.php on line 64

Here is my full PHP page code for the view_cart.php page:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php
session_start();
include_once("config.php");
$cart_items = 0;
foreach ($_SESSION['products'] as $cart_itm)
   {
       $cart_items ++;
   }

$Number_of_Arrays = $cart_items;  
echo "Number of Arrays: ".$Number_of_Arrays."";
$Per_Page = 10;   // Per Page  
$Page = $_GET["Page"];  
if(!$_GET["Page"])  
{  
$Page=1;  
}  

$Prev_Page = $Page-1;  
$Next_Page = $Page+1;  

$Page_Start = (($Per_Page*$Page)-$Per_Page);  
if($Number_of_Arrays<=$Per_Page)  
{  
$Num_Pages =1;  
}  
else if(($Number_of_Arrays % $Per_Page)==0)  
{  
$Num_Pages =($Number_of_Arrays/$Per_Page) ;  
}  
else  
{  
$Num_Pages =($Number_of_Arrays/$Per_Page)+1;  
$Num_Pages = (int)$Num_Pages;  
}  
$Page_End = $Per_Page * $Page;  
IF ($Page_End > $Number_of_Arrays)  
{  
$Page_End = $Number_of_Arrays;  
}  
?>

<?php
    if(isset($_SESSION["products"]))
    {
        $total = 0;
        echo '<form method="post" action="PAYMENT-GATEWAY">';
        echo '<ul>';
        $cart_items = 0;
$i = 0;
foreach ($_SESSION['products'] as $cart_itm)
   {
            $product_code = $cart_itm["code"];
           $queryy = "SELECT TOP 1 product_name,product_desc, price FROM products ORDER BY id OFFSET (($Page - 1) * $Per_Page) FETCH NEXT $Per_Page ONLY";
           $results = mssql_query($queryy, $mysqli);
           $obj = mssql_fetch_object($results);

            echo '<li class="cart-itm">';
            echo '<span class="remove-itm"><a href="cart_update.php?removep='.$cart_itm["code"].'&return_url='.$current_url.'">&times;</a></span>';
            echo '<div class="p-price">'.$currency.$obj->price.'</div>';
            echo '<div class="product-info">';
            echo '<h3>'.$obj->product_name.' (Code :'.$product_code.')</h3> ';
            echo '<div class="p-qty">Qty : '.$cart_itm["qty"].'</div>';
            echo '<div>'.$obj->product_desc.'</div>';
            echo '</div>';
            echo '</li>';
            $subtotal = ($cart_itm["price"]*$cart_itm["qty"]);
            $total = ($total + $subtotal);

            echo '<input type="hidden" name="item_name['.$cart_items.']" value="'.$obj->product_name.'" />';
            echo '<input type="hidden" name="item_code['.$cart_items.']" value="'.$product_code.'" />';
            echo '<input type="hidden" name="item_desc['.$cart_items.']" value="'.$obj->product_desc.'" />';
            echo '<input type="hidden" name="item_qty['.$cart_items.']" value="'.$cart_itm["qty"].'" />';
            $cart_items ++;

        }

        echo '</ul>';
        echo '<span class="check-out-txt">';
        echo '<strong>Total : '.$currency.$total.'</strong>  ';
        echo '</span>';
        echo '</form>';
        echo '<a href="checkout.php">Checkout</a>';
    }

?>
</body>
</html>

Here is my config.php page's complete code:

<?php
$mysqli = mssql_connect('dag','gfa','dca');  
$objConnectee = mssql_select_db('gba',$mysqli ); 
?>

Thank you for any help. All help is appreciated.

Kelsey
  • 795
  • 3
  • 15
  • 39

0 Answers0