SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Returning Random Table Row...

    Is it just me or does this seem too simple? Would it work?

    PHP Code:
    $ad $DB_site->query ("select banner from banner);
    $adbanner = = array_rand ($ad[banner], 1); 
    Wayne Luke
    ------------


  2. #2
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $ad $DB_site->query ("select banner from banner order by rand() limit 1); 
    Doesn't this do the same thing?
    Aaron Brazell
    Technosailor



  3. #3
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello, i just saw a minor error

    isn't it ment tobe

    PHP Code:
    $ad $DB_site->query ("select banner from banner order by rand() limit 1"); 

  4. #4
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Sketch
    PHP Code:
    $ad $DB_site->query ("select banner from banner order by rand() limit 1); 
    Doesn't this do the same thing?
    Never looked for this at MySQL's documentation because well frankly everytime I did in the past, it just didn't have the functionality.
    Wayne Luke
    ------------


  5. #5
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah...what alkaif said...whoops on the "

    Yeah, Wayne, I think that should do the same thing and you make mysql do the work instead of php...always more desirable. Especially for vBulletin.

    Aaron
    Aaron Brazell
    Technosailor



  6. #6
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by W. Luke
    Never looked for this at MySQL's documentation because well frankly everytime I did in the past, it just didn't have the functionality
    Huh? You mean you were using a version of MySQL that didn't support it or you think it didn't work properly?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  7. #7
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by seanf
    Huh? You mean you were using a version of MySQL that didn't support it or you think it didn't work properly?

    Sean
    No... I have found it easier to implement commen DBMS functionality in PHP than to wait for MySQL to have support for it so I don't bother looking. MySQL is great for simple queries but hell if you want to do anything sophisticated. Some of that should change with 4.0 but they need to increase functionality and stop worrying so much about speed. All the speed in the world is useless if you can't do the query to begin with.
    Wayne Luke
    ------------


  8. #8
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's been there since 3.23.3

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  9. #9
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I think you are confused... This is one little function that I never needed before now. When I did need it, I didn't bother looking at MySQL's documentation because I could do it in PHP.

    If MySQL had features like this a year ago (3.22 days) to make it a robust system instead of sacrificing all functionality for speed, I would have been a lot more eager to see if they supported it.

    In my book the standard installation still doesn't support necessary features needed in a modern DBMS. Things like Views, Sub-Selects, Stored Procedures, Triggers, Foreign Key Support (Referential Integrity), Tablespaces (for disk management) and many more things. A version number of 3.XX implies a little longetivity and stability so features should be there. Don't get me wrong, raw speed is nice but unless you can utilize the system to do most of that work, it is worthless.
    Wayne Luke
    ------------


  10. #10
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by W. Luke
    If MySQL had features like this a year ago (3.22 days) to make it a robust system instead of sacrificing all functionality for speed, I would have been a lot more eager to see if they supported it
    It did! I'm not sure exactly when it was added. Look at Kevin's post here from 09-Aug-2000

    I do agree that a lot of things are missing, but what's there is there

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  11. #11
    Hi there! Owen's Avatar
    Join Date
    Jan 2000
    Location
    CA
    Posts
    1,165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The mySQL order by rand is great when you need to fetch large quantities of data and don't want to have to do 2 queries or load all the data into memory. It's actually quite efficient for things like picking random advertisments to show (with a small amount of data and a lot to gain by the reduced number queries).

    Owen

  12. #12
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just for the record,
    from my MySQL book (new riders) I read that:
    As of MySQL 3.23.2, you can use ORDER BY RAND() to sort results randomly.

    So as W.Luke said it was not available at 3.22 days.



    pippo
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  13. #13
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by seanf
    It's been there since 3.23.3

    Sean
    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  14. #14
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sean,
    I didn't read that...
    mea culpa, mea culpa, mea maxima culpa


    So my book confirm with the tollerance of 1 sub-subversion what you said!


    pippo
    Last edited by pippo; Nov 2, 2002 at 09:52.
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03


Bookmarks

Posting Permissions

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