Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6912911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:09:03+00:00 2026-05-27T09:09:03+00:00

i need to get the latest order (from our custon admin panel). here’s my

  • 0

i need to get the latest order (from our custon admin panel). here’s my query:

select * 
from order 
  left join customer 
    on (customer.id = order.fk_cid) 
where date = curdate() 
order by time desc 
limit 1;

this output everything from orders and customers which i need except 1 therefore that is why i use the *

here’s my table structure:

order table: 
id, fk_cid, date, time

customer table: 
id, name, lastname, street, city, zip, country, phone, email, lastlogin

now, in my php i have:

$result = mysql_query("
    select * 
    from `order` 
    left join customer 
    on (customer.id = order.fk_cid) 
    where date = curdate() 
    order by time desc 
    limit 1");
$row = mysql_fetch_assoc($result, MYSQL_ASSOC);

at this point my order is not correct, why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:09:03+00:00Added an answer on May 27, 2026 at 9:09 am

    Your customers.id is overwriting the order.id because you are using the same column name.

    select * 
    from `order` 
    left join customer on (customer.id = order.fk_cid) 
    where date = curdate() order by time desc limit 1;
    +------+--------+------------+----------+------+-------+------
    | id   | fk_cid | date       | time     | id   | name  | ....
    +------+--------+------------+----------+------+-------+------
    |    1 |      2 | 2011-11-30 | 07:01:23 |    2 | asasd | ....
    +------+--------+------------+----------+------+-------+------
    1 row in set (0.03 sec)
    

    As you can see in this example you have two id, so PHP when retrieve the data using mysql_fetch_assoc it overwrites the second id because it’s the same key in the array. To fix this, you will have to specify the columns in your query:

    select `order`.id AS order_id, customer.id AS customer_id, customer.name /* etc... */
    

    This will output:

    Also, I recommend to use different name for your tables and fields. order, date, time since they are reserved word (in case you forget for use the ` ).

    Array
    (
        [order_id] => 1
        [customer_id] => 2
        // etc...
    )
    

    Also here’s a topic you should read: Why is SELECT * considered harmful?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get a list of Articles sorted by the latest Comment from
I need to get the latest X rows. So I do something like SELECT
I need a single query that is similar to SELECT datetime FROM blog WHERE
I need to get a log of user access to our SQL Server so
I need to select a top row for each category from a known set
Possible Duplicate: I need a good way to get data from a thread to
is ite possible to make an mysql query in which you get the latest
I tried this select posts.id, posts.title from posts inner join ( select post_id,max(created) from
I need to get the latest records, which are repeated more than two times.
Just need get some vals located in application.ini(main ini) in the Controller plugin I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.