1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.
  2. Better Analytics for WordPress Get It Free

Display sorted MYSQL database on website using PHP

Discussion in 'PHP' started by heenap, Jun 27, 2012.

  1. #1
    I am planning to improve the member pages section on my website. I have the data in a MYSQL database.

    I want to sort out the data alphabetically based on the users' First name. Presently the link to each user's member page is being displayed on the same page randomly (a colleague helped me out with that part. I am not very good with PHP and MYSQL). However, as the database is increasing the page is taking a long time to load.

    Hence I wish to sort out the members into different HTML pages for ones with first names beginning with A, another one for B, and so on. I know I will require some PHP for that but I am a bit confused.

    Also, will doing this segregation compromise the security aspect by any chance?

    Thanks for your help in advance
     
    Solved! View solution.
    heenap, Jun 27, 2012 IP
  2. #2
    Let's say you want to list ALL First Names in the table "People" in alphabetical order with the first letter beginning with A. You would use:

    SELECT firstname, lastname FROM People WHERE firstname WHERE LIKE 'a%' ORDERBY firstname ASC;

    "ORDERBY" sorts. ASC would be Ascend. DESC would be DESCEND.

    "LIKE" is a WHERE operator that searches for a pattern. The "%" is like the asterisk "*" which tells mysql "look for anything after this symbol"
     
    NetStar, Jun 27, 2012 IP
  3. Simple Boot

    Simple Boot Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    SELECT * FROM users WHERE first_name LIKE "$firstLetter%" ORDER BY users ASC
    
    Code (markup):
    Edit: NetStar apparently was faster than me ..
     
    Simple Boot, Jun 27, 2012 IP
  4. heenap

    heenap Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Got it. Thank you so much for your help both of you :D
     
    heenap, Jun 27, 2012 IP
  5. NetStar

    NetStar Well-Known Member

    Messages:
    1,577
    Likes Received:
    253
    Best Answers:
    19
    Trophy Points:
    135
    #5
    I placed an extra WHERE in mine.. just disregard it
     
    NetStar, Jun 28, 2012 IP