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.

Select from one table and sort by another table...

Discussion in 'PHP' started by LazyD, Mar 24, 2007.

  1. #1
    Im sure it sounds dumb but my setup is as follows:

    I have a table with all listing information, name, address, etc.

    I have another table that contains the number clicks a certain ID has recieved, the ID is the same ID used in the table with the listing info.. For example:

    Table - listingInfo
    listingID - 1
    listingName - Joe Smith

    listingID - 2
    listingName - Jane Smith

    table - listingClicks
    clickID - 1 (That is referring to listingID 1 (Joe Smith in this case))
    applyClick - (# of clicks that listing as recieved)

    So again, what i would like to do, is select and output all of the listings in listingInfo table but I would like to sort them by number of clicks.. Is this possible in my current configuration?
     
    LazyD, Mar 24, 2007 IP
  2. Alam

    Alam Active Member

    Messages:
    316
    Likes Received:
    91
    Best Answers:
    0
    Trophy Points:
    68
    #2
    you can try


    select * from listingInfo,listingClicks where listingInfo.listingID=listingClicks.clickID order by listingClicks.applyClick desc;
     
    Alam, Mar 25, 2007 IP
    LazyD likes this.
  3. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Looking at your query, that would only be selecting 1 listing, I need to output them all..
     
    LazyD, Mar 25, 2007 IP
  4. Robert Plank

    Robert Plank Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Alam's query WILL output them all, if the listingInfo and listingClicks tables have a 1 to 1 relationship as you described. He's doing a join... did you try the query yourself?
     
    Robert Plank, Mar 26, 2007 IP
    LazyD likes this.
  5. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I apologize to you Alam, your query worked perfectly..

    Robert, thank you for pointing out that I am a dee dee dee, I didnt bother to try his query assuming it didnt work, +rep to both of you
     
    LazyD, Mar 28, 2007 IP
  6. Alam

    Alam Active Member

    Messages:
    316
    Likes Received:
    91
    Best Answers:
    0
    Trophy Points:
    68
    #6
    :)

    I am happy to know that my script is serving u well :d
     
    Alam, Mar 29, 2007 IP