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 ???
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 ???
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.
Buntine > www.buntinedesign.com.au
I aint used the RAND function in MySQL for ages, but as far as i can remember it's actually this:might be wrong thoCode:SELECT RAND(columnName) FROM tableName
Download Firebird now!
or you could try RAND(*)
Buntine > www.buntinedesign.com.au
OK, thanx
buntine can u explain that with the PHP you told ...
Can u post here the php code ???
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!
I think he means random row? (common mistake)
Buntine's answer will select a random row.
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().
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 ...
Oops, I meant "row "aranoid:
aranoid:
aranoid:
aranoid: