|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I would like to pull a randomly selected entery out of a database & have tried the following command:
#!/usr/local/bin/php4 <? $db_name = "******"; $table_name = "rand"; $connection = @mysql_connect ("****", "*****", "****") or die("Couldn't connect."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $sql = "SELECT *, RAND() AS r FROM rand ORDER BY r LIMIT 1;"; FROM $table_name "; $result = @mysql_query($sql,$connection) or die("Couldn't execute query."); while ($row = mysql_fetch_array($result)) { $id = $row[0]; echo "$id" "; } ?> Which only throws back an error message. Any help please. JD (London) |
|
#2
|
||||
|
||||
|
try this instead:
PHP Code:
|
|
#3
|
|||
|
|||
|
Sorry onslaught I should have said, I'm using an older version of MySQL. I think the code you've given will only work on the newer versions.
|
|
#4
|
||||
|
||||
|
Versions 3.23 & up.
|
|
#5
|
|||
|
|||
|
I'm affraid my ISP uses 3.22 & down!
JD |
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > Help please with "Random Selection" |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|