Jump to content


Photo

Really stuck with this sort


  • Please log in to reply
4 replies to this topic

#1 wild_dog

wild_dog
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 29 May 2006 - 07:24 AM

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




#2 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 29 May 2006 - 07:51 AM

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..
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#3 wild_dog

wild_dog
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 29 May 2006 - 08:22 AM

[!--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) View Post[/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

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


#4 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 29 May 2006 - 09:13 AM

You can add a field in the cart items table (add_time) and sort the query on this field

$ATC_itemTime = now();



hth...
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 29 May 2006 - 07:50 PM

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?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users