Paginating a `View Cart` Page using PHP - php

I am trying to paginate my PHP page by ten results per page. Currently the page shows all results at once. I did look up some tutorials on pagination but I cannot seem to figure out how to implement them into the current PHP page. The PHP page is called view_cart.php and it essentially retrieves the cached products that were added by the user via a shopping cart page and displays them on this page. I am just looking for a few hints to point me in the right direction, not for someone to do my work for me.
This is the view_cart.php page code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
session_start();
include_once("config.php");
if(isset($_SESSION["products"]))
{
$total = 0;
echo '<form method="post" action="PAYMENT-GATEWAY">';
echo '<ul>';
$cart_items = 0;
foreach ($_SESSION["products"] as $cart_itm)
{
$product_code = $cart_itm["code"];
$queryy = "SELECT TOP 1 product_name,product_desc, price FROM products WHERE product_code='$product_code'";
$results = mssql_query($queryy, $mysqli);
$obj = mssql_fetch_object($results);
echo '<li class="cart-itm">';
echo '<span class="remove-itm">×</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 'Checkout';
}else{
echo 'Your Cart is empty';
}
?>
<?php
date_default_timezone_set('America/Edmonton');
?>
<?php echo date("D M d, Y G:i a"); ?>
</body>
</html>
This is the config.php page code:
<?php
$mysqli = mssql_connect('gd','Gad','Rdgaf!');
$objConnectee = mssql_select_db('Gdaddf',$mysqli );
?>
Thank you for any help. All help is appreciated.

You will have url parameters: start and count.
Use them in the sql query, like LIMIT $_GET['start'], $_GET['count']
The last thing is to render links to the "Next" and "Previous" page. (and to "First", "Last", 1,2,3,4....). Those links will include parameters start and count.
For example, the "Next" link will contain url with parameters:
"view_cart.php?start=" . ($_GET['start'] + $_GET['count']) . "&count=" . $_GET['count']
Beware of the total record count to not overflow.

Related

how to pass a retried database data to another page?

I am trying to make a simple booking form.
1st showing available cities and packages in a page from database
when the user clicks on the BOOK button in the page, the page will redirect to the action page where the selected form/package should be added to the booking table automatically and send a confirmation mail.
The following code generates the available packages from the database:
include 'inc/db_connect.php';
//working connection to the DB
$sql="SELECT pkg, fcity, dcity, price, details FROM tour_package WHERE fcity='".$fcity_search."' ORDER BY fcity ASC";
$sqlresult=mysqli_query($con,$sql);
$afct=mysqli_affected_rows($con);
while($pkg=mysqli_fetch_array($sqlresult,MYSQLI_ASSOC)){
$num[]=$pkg['pkg'];
$fcity[]=$pkg['fcity'];
$dcity[]=$pkg['dcity'];
$price[]=$pkg['price'];
$details[]=$pkg['details'];
$num++;
}
$i=0;
$book_btn_id = 1;
while($i < $afct)
{
echo '<form action="book_tour_action.php">';
$num_var_to_db = $num[$i];
echo '<span class="search-class-row"><div class="search-results-label">Package : </div>'.$num[$i].'<br/></span>';
echo '<span class="search-class-row"><div class="search-results-label">From : </div>'. $fcity[$i].'<br/></span>';
echo '<span class="search-class-row"><div class="search-results-label">Destination : </div>' . $dcity[$i].'<br/></span>';
echo '<span class="search-class-row"><div class="search-results-label">Price : </div>' .$price[$i].'<br/></span>';
echo '<span class="search-class-row"><div class="search-results-label">Details :</div>' . $details[$i].'<br/></span>';
//echo ' BOOK ';
echo '<input type="submit" value="BOOK" class="booking-btn" name="bb'.$book_btn_id++.'">';
echo '<br><br/><hr/>';
$i++;
echo '</form>';
}
I've set a dynamic name to the BOOK button.
book_tour_action.php:
echo $num_var_to_db;
$sql = "INSERT INTO booking (num_var_to_db)
VALUES ('$num_var_to_db')";
But it says UNDEFINED VARIABLE when the BOOK button is clicked.
So that means the data is not passed to book_tour_action.php I guess.
How can I make it work?
You need to keep $num_var_to_db value in hidden input field in the form to get the value. Try do like below :
echo '<form action="book_tour_action.php">';
$num_var_to_db = $num[$i];
echo '<input type="hidden" name="num_var_to_db" value="'.$num_var_to_db.'">'
echo '<span class="search-class-row"><div class="search-results-label">Package : </div>'.$num[$i].'<br/></span>';
echo '<span class="search-class-row"><div class="search-results-label">From : </div>'. $fcity[$i].'<br/></span>';
echo '<span class="search-class-row"><div class="search-results-label">Destination : </div>' . $dcity[$i].'<br/></span>';
echo '<span class="search-class-row"><div class="search-results-label">Price : </div>' .$price[$i].'<br/></span>';
echo '<span class="search-class-row"><div class="search-results-label">Details :</div>' . $details[$i].'<br/></span>';
//echo ' BOOK ';
echo '<input type="submit" value="BOOK" class="booking-btn" name="bb'.$book_btn_id++.'">';
echo '<br><br/><hr/>';
$i++;
echo '</form>';
and in the php page you can do following to get the value:
$num_var_to_db = $_REQUEST['num_var_to_db'];

Insert multiple rows mysql

i have the following code:
<?php
session_start();
include_once("config.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View shopping cart</title>
<link href="style/style.css" rel="stylesheet" type="text/css"></head>
<body>
<br>
<div id="books-wrapper">
<!-- #content to center the menu -->
<div id="content">
<!-- This is the actual menu -->
<ul id="darkmenu">
<li>Home</li>
<li>Catalogue</li>
<li>Search</li>
<li>Cart</li>
<li>Orders</li>
</ul>
<div id = "welcome" >
Welcome, <?=$_SESSION['login_user']?>! <br> Logout
</div>
</div>
<br><br>
<h1 id = "mainHeader" >View Cart</h1>
<br>
<div class="view-cart">
<?php
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
if(isset($_SESSION["books"]))
{
$total = 0;
echo '<form method="post" action="">';
echo '<ul>';
$cart_items = 0;
foreach ($_SESSION["books"] as $cart_itm){
$ISBN = $cart_itm["ISBN"];
$results = $mysqli->query("SELECT Title,BookDesc,Price FROM books WHERE ISBN='$ISBN'");
$obj = $results->fetch_object();
echo '<li class="cart-itm">';
echo '<span class="remove-itm">×</span>';
echo '<div class="p-Price">'.$currency.$obj->Price.'</div>';
echo '<div class="book-info">';
echo '<h3>'.$obj->Title.' (ISBN :'.$ISBN.')</h3> ';
echo '<div class="p-quantity">Quantity : '.$cart_itm["quantity"].'</div>';
echo '<div>'.$obj->BookDesc.'</div>';
echo '</div>';
echo '</li>';
$subtotal = ($cart_itm["Price"]*$cart_itm["quantity"]);
$total = ($total + $subtotal);
echo '<input type="hidden" name="item_name['.$cart_items.']" value="'.$obj->Title.'" />';
echo '<input type="hidden" name="item_code['.$cart_items.']" value="'.$ISBN.'" />';
echo '<input type="hidden" name="item_desc['.$cart_items.']" value="'.$obj->BookDesc.'" />';
echo '<input type="hidden" name="item_quantity['.$cart_items.']" value="'.$cart_itm["quantity"].'" />';
$cart_items ++;
}
echo '</ul>';
echo '<span class="check-out-txt">';
echo '<strong>Total : '.$currency.$total.'</strong> ';
echo '</span>';
echo '<button name="submit_btn" class="save_order">Save Order</button>';
echo '</form>';
if(isset($_POST['submit_btn']) ){
$insquery = "INSERT INTO `pending_orders` (`OrderNo`,`BookName`,`Quantity`,`TotalPrice`,`ISBN`,`StudentID`) VALUES (NULL, '" . $obj->Title . "', '" . $cart_itm['quantity'] . "', '" . $total . "', '" . $ISBN . "', '" . $_SESSION['login_user'] . "');";
$stmt = $mysqli->prepare($insquery);
$stmt->execute();
}
}
?>
</div>
</div>
</body>
</html>
The code is supposed to save a customers book order into a database, It works perfectly fine for ONE book. Line 76 to 81 has the insert statement.
however if the person has purchased two books then only the last book gets added to the database. Screenshots added:
This is what it looks like on my website. As you can see the person has selected two books to be purchased:
http://postimg.org/image/3kj1gvytx/
However this is what i get in my phpmyadmin site:
http://postimg.org/image/k85hs56xj/
We can see that only the second book (biology) gets stored in the database. as well as the total of the two books
Any ideas how i could fix the issue and store both books.
Thanks
<?php
session_start();
include_once("config.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View shopping cart</title>
<link href="style/style.css" rel="stylesheet" type="text/css"></head>
<body>
<br>
<div id="books-wrapper">
<!-- #content to center the menu -->
<div id="content">
<!-- This is the actual menu -->
<ul id="darkmenu">
<li>Home</li>
<li>Catalogue</li>
<li>Search</li>
<li>Cart</li>
<li>Orders</li>
</ul>
<div id = "welcome" >
Welcome, <?=$_SESSION['login_user']?>! <br> Logout
</div>
</div>
<br><br>
<h1 id = "mainHeader" >View Cart</h1>
<br>
<div class="view-cart">
<?php
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
if(isset($_SESSION["books"]))
{
$total = 0;
echo '<form method="post" action="">';
echo '<ul>';
$cart_items = 0;
foreach ($_SESSION["books"] as $cart_itm){
$ISBN = $cart_itm["ISBN"];
$results = $mysqli->query("SELECT Title,BookDesc,Price FROM books WHERE ISBN='$ISBN'");
$obj = $results->fetch_object();
echo '<li class="cart-itm">';
echo '<span class="remove-itm">×</span>';
echo '<div class="p-Price">'.$currency.$obj->Price.'</div>';
echo '<div class="book-info">';
echo '<h3>'.$obj->Title.' (ISBN :'.$ISBN.')</h3> ';
echo '<div class="p-quantity">Quantity : '.$cart_itm["quantity"].'</div>';
echo '<div>'.$obj->BookDesc.'</div>';
echo '</div>';
echo '</li>';
$subtotal = ($cart_itm["Price"]*$cart_itm["quantity"]);
$total = ($total + $subtotal);
echo '<input type="hidden" name="itemname_['.$cart_items.']" value="'.$obj->Title.'" />';
echo '<input type="hidden" name="itemcode_['.$cart_items.']" value="'.$ISBN.'" />';
echo '<input type="hidden" name="itemdesc_['.$cart_items.']" value="'.$obj->BookDesc.'" />';
echo '<input type="hidden" name="itemquantity_['.$cart_items.']" value="'.$cart_itm["quantity"].'" />';
echo '<input type="hidden" name="total_['.$cart_items.']" value="'.$total.'" />';
$cart_items ++;
}
echo '</ul>';
echo '<span class="check-out-txt">';
echo '<strong>Total : '.$currency.$total.'</strong> ';
echo '</span>';
echo '<button name="submit_btn" class="save_order">Save Order</button>';
echo '</form>';
if(isset($_POST['submit_btn']) ){
$item_array = array();
foreach($_POST as $key => $value) {
// echo "POST parameter '$key' has '$value';
$pieces = explode("_",$key)
if(strstr($pieces[0] == 'itemname')
{
$item_array[$pieces[1]]['BookName'] = $value;
}
if(strstr($pieces[0] == 'itemcode')
{
$item_array[$pieces[1]]['ISBN'] = $value;
}
if(strstr($pieces[0] == 'itemquantity')
{
$item_array[$pieces[1]]['Quantity'] = $value;
}
if(strstr($pieces[0] == 'total')
{
$item_array[$pieces[1]]['TotalPrice'] = $value;
}
}
$insquery = "INSERT INTO `pending_orders` (`OrderNo`,`BookName`,`Quantity`,`TotalPrice`,`ISBN`,`StudentID`) VALUES ";
foreach($item_array as $row)
{
$insquery .= "(NULL, '" . $row['BookName'] . "', '" . $row['Quantity'] . "', '" .$row['TotalPrice']. "', '" . $row['ISBN'] . "', '" . $_SESSION['login_user'] . "'),";
}
$insquery = substr($insquery, 0, -1);
$stmt = $mysqli->prepare($insquery);
$stmt->execute();
foreach($_POST as $row)
$insquery = "INSERT INTO `pending_orders` (`OrderNo`,`BookName`,`Quantity`,`TotalPrice`,`ISBN`,`StudentID`) VALUES (NULL, '" . $obj->Title . "', '" . $cart_itm['quantity'] . "', '" . $total . "', '" . $ISBN . "', '" . $_SESSION['login_user'] . "');";
$stmt = $mysqli->prepare($insquery);
$stmt->execute();
}
}
?>
</div>
</div>
</body>
</html>
you form the insert statement like above
As you don't know Ajax, you can do something like this:
1) Reset $result array, to select items again for MySQL query.
2) With while loop insert each selected value into DB.
reset($result);
while($row=mysqli_fetch_array($result))
{
$ins = mysqli_query($con, "Here goes insert statement for each");
}
EDIT
$ISBN = $cart_itm["ISBN"];
$con = mysqli_connect("localhost","root","","yourbasename");
$result = mysqli_query($con, "SELECT Title,BookDesc, Price FROM books
WHERE ISBN='$ISBN'");
while($row=mysqli_fetch_array($result)
{
$insert = mysqli_query($con, "INSERT.....");
}

PHP query based on sessions

HI I wanted to know how to restart a session in php. When I use the code given below in one of my pages it would work for the 1st time. When I refresh the page the previous session continues. So how can I start a new session when the page reloads?Thanks for the quick response.INCLUDED WHOLE CODE TO MAKE THINGS CLEAR
<?php
session_start();
include_once("config.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Shopping Cart</title>
<link href="style/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="products-wrapper">
<h1>Products</h1>
<div class="products">
<?php
//current URL of the Page. cart_update.php redirects back to this URL
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$results = $mysqli->query("SELECT * FROM shop ORDER BY product_code ASC");
if ($results) {
//fetch results set as object and output HTML
while($obj = $results->fetch_object())
{
echo '<div class="product">';
echo '<form method="post" action="cart_update.php">';
echo '<div class="product-content"><h3>'.$obj->product_name.'</h3>';
echo '<div class="product-info">';
echo 'Price '.$currency.$obj->price.' | ';
echo 'Qty <input type="text" name="product_qty" value="0" size="3" />';
echo '<button class="add_to_cart">Add To Cart</button>';
echo '</div></div>';
echo '<input type="hidden" name="product_code" value="'.$obj->product_code.'" />';
echo '<input type="hidden" name="type" value="add" />';
echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
echo '</form>';
echo '</div>';
}
}
?>
</div>
<div class="shopping-cart">
<h2>Your Shopping Cart</h2>
<?php
if(isset($_SESSION["shop"]))
{
$total = 0;
echo '<ol>';
foreach ($_SESSION["shop"] as $cart_itm)
{
echo '<li class="cart-itm">';
echo '<span class="remove-itm">×</span>';
echo '<h3>'.$cart_itm["name"].'</h3>';
echo '<div class="p-code"></div>';
echo '<div class="p-qty">Qty : '.$cart_itm["qty"].'</div>';
echo '<div class="p-price">Price :'.$currency.$cart_itm["price"].'</div>';
echo '</li>';
$subtotal = ($cart_itm["price"]*$cart_itm["qty"]);
$total = ($total + $subtotal);
}
echo '</ol>';
echo '<span class="check-out-txt"><strong>Total : '.$currency.$total.'</strong> Check-out!</span>';
echo '<span class="empty-cart">Empty Cart</span>';
}else{
echo 'Your Cart is empty';
}
?>
</div>
</div>
</body>
</html>
You may use session_destroy function in the end of your file.
<?php
session_start();
include_once("config.php");
/*your code*/
session_destroy();
?>
session_destroy — Destroys all data registered to a session
bool session_destroy ( void )
http://php.net/manual/en/function.session-destroy.php
You need to use session_destroy(); to destry a session and then you can start a new one
try to remove session first and start again
if(session_id() != '' || isset($_SESSION)) {
session_destroy();
session_start();
}
else {
session_start();
}
You have to destroy the session after your event.
<?php
session_start();
include_once("config.php");
//after doing your task with the session variable destroy session
session_destroy();
?>
<?php
#session_destroy(); // destroy session if exists
session_start();
include_once("config.php");
?>
UPDATE 2 :
<?php
if(isset($_SESSION))
{
session_destroy(); // destroy session if exists
}
session_start();
include_once("config.php");
?>
UPDATE 3 :
If you want to unset only $_SESSION['shop'] after using it
if(isset($_SESSION["shop"]))
{
// your code
unset($_SESSION['shop']); // unset your session after using it
}else{
echo 'Your Cart is empty';
}

MySQL separate in to DIV elements

I would greatly enjoy knowing how to separate the results of my query based on the "season" using PHP only. The products should be placed in separate divs according to what season they are for. I would also like to do this in the most efficient way possible. I have thought about his for some time and have failed both in a solution and in finding someone else's similar results on the internet. Please ignore the jquery, it is a leftover for something I may or may not use.
<?php
session_start();
include_once("config.php");
?>
<!DOCTYPE html>
<html>
<head>
<title>Shop</title>
<link rel="stylesheet" type="text/css" href="style/main.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0
/jquery.min.js"></script>
<script type="text/javascript" src="script/jquery.simplyscroll.min.js"></script>
<script type="text/javascript">
(function($) {
$(function() {
$("#scroller").simplyScroll();
});
})(jQuery);
</script>
</head>
<body>
<div id="container">
<div id="header">
<div id="menu">
<ul>
<li>Home</li>
<li>About</li>
<li>Shop</li>
<li>Contact</li>
</ul>
</div>
</div>
<div id="content">
<?php
//current URL of the Page. cart_update.php redirects back to this URL
$current_url = base64_encode("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
//$results = $db->query('SELECT id, name, thumb, description, price, season FROM products
BY season ASC');
foreach($db->query('SELECT id, name, thumb, description, price FROM products BY season
ASC') as $results){
if ($results) {
//output results from database
$last_season = 1;
echo '<div class="products">';
while($obj = $results->fetch_object())
{
if ($last_season != $obj->season){
echo '</div><div class="products">';
}
echo '<div class="product">';
echo '<form method="post" action="cart_update.php">';
echo '<div class="product-thumb"><img src="image/'.$obj->product_img_name.'"></div>';
echo '<div class="product-content"><h3>'.$obj->product_name.'</h3>';
echo '<div class="product-desc">'.$obj->product_desc.'</div>';
echo '<div class="product-info">Price '.$currency.$obj->price.' <button
class="add_to_cart">Add To Cart</button></div>';
echo '</div>';
echo '<input type="hidden" name="product_code" value="'.$obj->product_code.'" />';
echo '<input type="hidden" name="type" value="add" />';
echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
echo '</form>';
echo '</div>';
$last_season = $obj->season;
}
echo '</div>';
}
}
?>
<div id="shopping-cart">
<h2>Your Shopping Cart</h2>
<?php
if(isset($_SESSION["products"]))
{
$total = 0;
echo '<ol>';
foreach ($_SESSION["products"] as $cart_itm)
{
echo '<li class="cart-itm">';
echo '<span class="remove-itm"><a href="cart_update.php?removep='.$cart_itm["code"].'&
return_url='.$current_url.'">×</a></span>';
echo '<h3>'.$cart_itm["name"].'</h3>';
echo '<div class="p-code">P code : '.$cart_itm["code"].'</div>';
echo '<div class="p-qty">Qty : '.$cart_itm["qty"].'</div>';
echo '<div class="p-price">Price :'.$currency.$cart_itm["price"].'</div>';
echo '</li>';
$subtotal = ($cart_itm["price"]*$cart_itm["qty"]);
$total = ($total + $subtotal);
}
echo '</ol>';
echo '<span class="check-out-txt"><strong>Total : '.$currency.$total.'</strong> Check-out!</span>';
echo '<span class="empty-cart"><a href="cart_update.php?emptycart=1&
return_url='.$current_url.'">Empty Cart</a></span>';
}else{
echo 'Your Cart is empty';
}
?>
</div>
</div>
<div id="footer">Footer goes here.</div>
</div>
</body>
</html>
I am getting an error on line 44, which is the start of the "foreach" statement. I am again at a loss. Thank you a ton for your help so far. If I can get this working, with help of course, I will be extremely excited and in your debt.
Here's a loop that will create a new div each time the season changes in a new row. You will need to change the query to order the results by season, e.g.
ORDER BY season ASC
Here's the loop:
if ($results) {
//output results from database
$last_season = 1; //initial value
echo '<div class="season">'; //opens first season div
while($obj = $results->fetch_object()){
if ($last_season != $obj->season){
echo '</div><div class="season">';
}
echo '<div class="product">';
echo '<form method="post" action="cart_update.php">';
echo '<div class="product-thumb"><img src="image/'.$obj->product_img_name.'"></div>';
echo '<div class="product-content"><h3>'.$obj->product_name.'</h3>';
echo '<div class="product-desc">'.$obj->product_desc.'</div>';
echo '<div class="product-info">Price '.$currency.$obj->price.' <button class="add_to_cart">Add To Cart</button></div>';
echo '</div>';
echo '<input type="hidden" name="product_code" value="'.$obj->product_code.'" />';
echo '<input type="hidden" name="type" value="add" />';
echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
echo '</form>';
echo '</div>';
$last_season = $obj->season;
}
echo '</div>'; //closes final season div
}
Regarding the line 44 error in the foreach, I believe what you want there instead of a foreach is simply:
$results = $db->query('SELECT id, name, thumb, description, price FROM products BY season
ASC'); //remember to remove the closing bracket of the foreach

Shopping Cart's `View Cart Items` Page is not Paginating Properly

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">×</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 'Checkout';
}
?>
</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.

Categories