+ Post New Thread
Results 1 to 3 of 3
Coding Thread, PHP/MySQL in Coding and Web Development; Just wondering if someone can help here. I have a PHP script with an SQL query. The MySQL query picks ...
  1. #1
    Silvor's Avatar
    Join Date
    Oct 2007
    Posts
    122
    Thank Post
    18
    Thanked 15 Times in 10 Posts
    Rep Power
    17

    PHP/MySQL

    Just wondering if someone can help here.

    I have a PHP script with an SQL query. The MySQL query picks up data from one table called
    'info'. It has the following fields (as I am just testing at the moment)

    [ID | UserID | Email | Phone]

    I have another table in the mysql database called 'users'. This has

    [ID | UserID | Surname | Forename]

    The UserID is the same. When a 'user' submits their 'info', it submits their info into the info database.

    I am wanting to display results from 'info' in order of 'surname' by using the "UserID".
    So that would use the UserID to cross reference to find the users username and display the phone numbers and email addresses in order of surname.
    (because part of the PHP script already has a function to display the username in the table of info by picking up the forename, surname based on the userID).

    Does anyone know the correct MySQL statement I would use to achieve this?
    I seem to remember doing it before but can't get it to work anymore the way I thought was possible.

    Many thanks,
    Mike
    Last edited by Silvor; 12th May 2010 at 02:22 PM.

  2. #2

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,866
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Code:
    SELECT u.UserID, u.Surname, u.Forename, i.Email, i.Phone FROM users AS u LEFT JOIN info AS i ON u.UserID=i.UserID ORDER BY surname, forename ASC;

  3. Thanks to powdarrmonkey from:

    Silvor (12th May 2010)

  4. #3
    Silvor's Avatar
    Join Date
    Oct 2007
    Posts
    122
    Thank Post
    18
    Thanked 15 Times in 10 Posts
    Rep Power
    17
    Many thanks :-)

SHARE:
+ Post New Thread

Similar Threads

  1. Best Site to learn php and mysql?
    By My220x in forum Coding
    Replies: 11
    Last Post: 23rd April 2008, 08:58 AM
  2. Can't get mysql and PHP to play together on IIS
    By dagza in forum Web Development
    Replies: 5
    Last Post: 20th January 2008, 03:38 PM
  3. PHP MYSQL Hit counter
    By Nij.UK in forum Web Development
    Replies: 9
    Last Post: 15th November 2006, 09:11 AM
  4. Php/MySQL Web Design
    By Adam in forum How do you do....it?
    Replies: 8
    Last Post: 18th July 2005, 04:13 PM
  5. php MySql
    By iking in forum Books and Manuals
    Replies: 0
    Last Post: 11th July 2005, 03:35 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •