Jump to content

Archived

This topic is now archived and is closed to further replies.

wild_dog

Really stuck with this sort

Recommended Posts

Hi there,

Im trying to write a function that does the following:

I have a form which has items from a mysql database. At the moment when you click
on an item from the page and add it to a cart the items are being displayed in random order.

I want the items to be displayed in the order they are clicked on

Any ideas??


Cheers


Share this post


Link to post
Share on other sites
please paste the query which you are using to get items in the cart, if the items are in session then please paste the code which you use to display cart items..

Share this post


Link to post
Share on other sites
[!--quoteo(post=378007:date=May 29 2006, 02:24 AM:name=wild_dog)--][div class=\'quotetop\']QUOTE(wild_dog @ May 29 2006, 02:24 AM) [snapback]378007[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi there,

Im trying to write a function that does the following:

I have a form which has items from a mysql database. At the moment when you click
on an item from the page and add it to a cart the items are being displayed in random order.

I want the items to be displayed in the order they are clicked on

Any ideas??
Cheers
[/quote]


Have a look below:

I was thinking of somehow assigning a key/id to each item as they are entered and keep a count. Then you fecth the items from the DB as they are added and just display them in the order the keys were assigned (but im thinking another table or two might need to be created for this?? )

Also if the user was then to come back and add more items the function would look for the max count as they were entered and add to the end of the list.

Got an idea??



==========================================================
<?php
//WA eCart Include
require_once("../WA_eCart/blade_cart_PHP.php");
session_start();
?>
<?php require_once('../Connections/blade.php'); ?>
<?php
$blade_cart->GetContent();
?>
<?php
$maxRows_Recordset1 = 5;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

$colname_Recordset1 = "-1";
if (isset($_POST['size'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_POST['size'] : addslashes($_POST['size']);
}
mysql_select_db($database_blade, $blade);
$query_Recordset1 = sprintf("SELECT ProdID, ProdName, ProdPrice FROM products WHERE ProdID = %s", $colname_Recordset1);
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $blade) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<?php
// WA eCart AddToCart
if (isset($_POST["blade_cart_1_ATC"]) || isset($_POST["blade_cart_1_ATC_x"])) {
$ATC_itemID = $_POST["blade_cart_1_ID_Add"];
$ATC_AddIfIn = 2;
$ATC_RedirectAfter = "../shopping_cart/cart.php";
$ATC_RedirectIfIn = "";
$ATC_itemName = "".$row_Recordset1['ProdName'] ."";// column binding
$ATC_itemDescription = "testdesc";// column binding
$ATC_itemWeight = floatval("0");// column binding
$ATC_itemQuantity = "".$_POST["blade_cart_1_Quantity_Add"] ."";// column binding
$ATC_itemPrice = floatval("".$row_Recordset1['ProdPrice'] ."");// column binding
$ATC_itemQuantity = floatval($ATC_itemQuantity);
if (is_numeric($ATC_itemQuantity) && $ATC_itemQuantity != 0) {
$blade_cart->AddToCart($ATC_AddIfIn, $ATC_RedirectIfIn, $ATC_itemID, $ATC_itemName, $ATC_itemDescription, $ATC_itemWeight, $ATC_itemQuantity, $ATC_itemPrice);
if ($ATC_RedirectAfter != "" && $blade_cart->redirStr == "") {
$blade_cart->redirStr = $ATC_RedirectAfter;
}
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != "") {
$_SESSION['WAEC_ContinueRedirect'] = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
}
else {
$_SESSION['WAEC_ContinueRedirect'] = $_SERVER['PHP_SELF'];
}
}
}
?><?php

=============================================================

Share this post


Link to post
Share on other sites
You can add a field in the cart items table (add_time) and sort the query on this field

$ATC_itemTime = now();



hth...

Share this post


Link to post
Share on other sites
You asked this question yesterday and you were advised to record the time but chose to ignore it.

[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=94438&hl=\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...topic=94438&hl=[/a]

Now you ask it again and get the same advice from another source.

1. Don't double post.

2. If you are just going to reject any advice offered, why post at all?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.