miltonbanks Posted September 3, 2007 Share Posted September 3, 2007 hi guys, i want to randomly select 5 different values from a database, from one table, and then just assign those values to some php variable. any help will be much appreciated!!! thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/67715-random-selection/ Share on other sites More sharing options...
teng84 Posted September 3, 2007 Share Posted September 3, 2007 select yourfield from table order by field RAND() limit 5 ;D Quote Link to comment https://forums.phpfreaks.com/topic/67715-random-selection/#findComment-340187 Share on other sites More sharing options...
miltonbanks Posted September 3, 2007 Author Share Posted September 3, 2007 hey, thanks for your reply, but how would i go about assigning those five vaules? sorry if this is a stupid question, i am new to php and mysql!! Quote Link to comment https://forums.phpfreaks.com/topic/67715-random-selection/#findComment-340196 Share on other sites More sharing options...
teng84 Posted September 3, 2007 Share Posted September 3, 2007 http://w3schools.com/php/php_mysql_select.asp Quote Link to comment https://forums.phpfreaks.com/topic/67715-random-selection/#findComment-340199 Share on other sites More sharing options...
miltonbanks Posted September 3, 2007 Author Share Posted September 3, 2007 thanks again for your help, but i cant seem to get it to work, i have managed to print the rows into a table, but cant seem to assign the values to variables $query = "SELECT * FROM table ORDER BY Rand() LIMIT 5"; $result = mysql_query($query); echo "<table>"; while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td></tr>"; ////what i want is $value1=$row[0] , or something like that } echo "</table>"; } else { echo "database down } ?> again, thanks for your time!!!! Quote Link to comment https://forums.phpfreaks.com/topic/67715-random-selection/#findComment-340227 Share on other sites More sharing options...
teng84 Posted September 3, 2007 Share Posted September 3, 2007 $row[2] $row --- array [2] ---index of array that is supposedly from your db so syntax should be $row[field of table you query]; it should go something like cho "<tr><td>$row[name]</td><td>$row[add]</td><td>$row[etc]</td></tr>"; the example in that site is very clear try to read that again that will help you ;D Quote Link to comment https://forums.phpfreaks.com/topic/67715-random-selection/#findComment-340229 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.