PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 300,436 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,476 people online right now. Registration is fast and FREE... Join Now!




Select a customers last order from database

 

Select a customers last order from database, Cubecart 4

Chalie9809

3 Jul, 2009 - 10:29 PM
Post #1

New D.I.C Head
*

Joined: 28 Jan, 2009
Posts: 37



Thanked: 4 times
My Contributions
Hey, Im trying to select a customers latest order made from the database:

CODE
            $last_order = $db->select("SELECT cart_order_id FROM ".$glob['dbprefix']."CubeCart_order_sum WHERE time = (SELECT MAX(time) FROM ".$glob['dbprefix']."CubeCart_order_sum) & customer_id = ".$db->mySQLsafe($cc_session->ccUserData['customer_id'])."");


Does that look like it will work? and will it return only "cart_order_id"?

Cheers

Charlie

This post has been edited by Chalie9809: 3 Jul, 2009 - 10:34 PM

User is offlineProfile CardPM
+Quote Post


noorahmad

RE: Select A Customers Last Order From Database

3 Jul, 2009 - 10:45 PM
Post #2

Webmaster
Group Icon

Joined: 12 Mar, 2009
Posts: 2,018



Thanked: 125 times
Dream Kudos: 1350
My Contributions
i can't get your code but i tried my best to Debug it
SQL
"SELECT cart_order_id FROM ".$glob['dbprefix']."CubeCart_order_sum, MAX(time) FROM tblname WHERE customer_id = 7"


and here is my code
SQL
"SELECT , CustID, CustName,max( `CreationTime` ) FROM tblCust WHERE CustID =1";

hope it help you smile.gif
User is online!Profile CardPM
+Quote Post

Chalie9809

RE: Select A Customers Last Order From Database

3 Jul, 2009 - 11:08 PM
Post #3

New D.I.C Head
*

Joined: 28 Jan, 2009
Posts: 37



Thanked: 4 times
My Contributions
Thankyou, but ill have to explain a bit more.

Key:
cart_order_id = Order ID
customer_id =Customer ID
time = Time at which order was subimitted


Basic Structure:
CODE
TABLE: CubeCart_order_sum
##############################################
# cart_order_id  # customer_id  #   time   #
##############################################
#      123456     #      7      #    12654  #
#      982455     #      7      #    65498  #
#      982737     #      7      #    99999  #
#      369425     #      7      #    26437  #
#      126527     #      5      #    98774  #
#      963762     #      4      #    16642  #
##############################################



I want to return the most recent (highest time value) Order ID

Heres the breakdown of my original code:
SQL
"SELECT cart_order_id FROM CubeCart_order_sum WHERE time = (SELECT MAX(time) FROM CubeCart_order_sum) & customer_id = 7"



So what I want to return is:

QUOTE
# 982455 # 7 # 65498 #
# 982737 # 7 # 99999 #
# 369425 # 7 # 26437 #
# 126527 # 5 # 98774 #




982737


Cheers

This post has been edited by Chalie9809: 3 Jul, 2009 - 11:14 PM
User is offlineProfile CardPM
+Quote Post

noorahmad

RE: Select A Customers Last Order From Database

3 Jul, 2009 - 11:15 PM
Post #4

Webmaster
Group Icon

Joined: 12 Mar, 2009
Posts: 2,018



Thanked: 125 times
Dream Kudos: 1350
My Contributions
are you getting data from one table
User is online!Profile CardPM
+Quote Post

Chalie9809

RE: Select A Customers Last Order From Database

3 Jul, 2009 - 11:18 PM
Post #5

New D.I.C Head
*

Joined: 28 Jan, 2009
Posts: 37



Thanked: 4 times
My Contributions
Yes only one table.
User is offlineProfile CardPM
+Quote Post

noorahmad

RE: Select A Customers Last Order From Database

4 Jul, 2009 - 02:10 AM
Post #6

Webmaster
Group Icon

Joined: 12 Mar, 2009
Posts: 2,018



Thanked: 125 times
Dream Kudos: 1350
My Contributions
try this
SQL
SELECT * FROM CubeCart_order_sum WHERE time = SELECT MAX(time) And customer_id = 7


or
SQL
SELECT * FROM tblcustomres WHERE CreationTime = (SELECT Max(CreationTime ) ) and custid=


Hope is help You smile.gif
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 12:58AM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month