I want to select 4 random rows from a mysql database that doesn't have numerical id's. The primary key is a column called name, which contains names
What I want is to select 4 random rows from that table, and right now im using this query:
It works, but not as I wanted it to work, since it only returns one row, at random.
So then I tried to loop it and get 4 rows, but some times I get duplicate rows, so what I need is a way to get all four rows at the same time, so they are not duplicate.
Thanks in advance!
What I want is to select 4 random rows from that table, and right now im using this query:
| Code: |
|
$nr = 4; //number of rows to select $sql = 'SELECT * FROM `enlaces` ORDER BY rand() LIMIT 0,'.$nr.';'; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ echo row['name'].'-'.row['url']; return true; } |
It works, but not as I wanted it to work, since it only returns one row, at random.
So then I tried to loop it and get 4 rows, but some times I get duplicate rows, so what I need is a way to get all four rows at the same time, so they are not duplicate.
Thanks in advance!
