Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 10 of 10
  1. #1
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    I would like to make a code in PHP where it will selects a random column of a certain table in SQL and read its data ...
    Is that simple ???
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    735
    Member #
    1935
    the folowing SQL query may work:

    $sqlQuery = "SELECT * FROM tableName ORDER BY RAND() LIMIT 1";

    Another method is to select all the rows from a table with the standard "SELECT * FROM tableName" query and then display one random row using PHP code.

  4. #3
    Member Black Vivi's Avatar
    Join Date
    Apr 2003
    Location
    UK
    Posts
    75
    Member #
    1072
    I aint used the RAND function in MySQL for ages, but as far as i can remember it's actually this:
    Code:
    SELECT RAND(columnName) FROM tableName
    might be wrong tho
    Download Firebird now!

  5. #4
    Senior Member
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    735
    Member #
    1935
    or you could try RAND(*)

  6. #5
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    OK, thanx
    buntine can u explain that with the PHP you told ...
    Can u post here the php code ???
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations

  7. #6
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    I don't think that you can select a random column, only random rows. However, you can use PHP to randomly pick one of the elements that fetch_array() returns.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  8. #7
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    I think he means random row? (common mistake)

    Buntine's answer will select a random row.

  9. #8
    Senior Member tibberous's Avatar
    Join Date
    Aug 2003
    Posts
    195
    Member #
    2535
    Thanks buntine. I normally just get the whole thing, then grab the row with PHP, I'll garentee this is faster. Never knew you could do an order by Rand().

  10. #9
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    Look, I want to create a random image script that randomly selects an image and its url (located in mySQL) and display it to the user ...
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations

  11. #10
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    Oops, I meant "row " aranoid: aranoid: aranoid: aranoid:
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations


Remove Ads

Posting Permissions

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

Search tags for this page

how to make random column in php

,

randomize columns in php

,

randomly select a field in sql

,

select random fields t-sql

,

sql rand column

,

sql select random column

,

sql select random columns

Click on a term to search for related topics.
All times are GMT -6. The time now is 03:03 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com