SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: PHP and Mysql Random
-
Dec 11, 2008, 18:21 #1
PHP and Mysql Random
Hi
just wanted to know the solution for this problem. this has been bugging me for days!!
not really sure if this is a php thing or mysql thing and sorry in advance if i posted this in the wrong channel.
well here it goes...
say i have 2 mysql queries
$query_1 = "SELECT * FROM `table` ORDER BY RAND()";
$query_2 = "SELECT * FROM `table` ORDER BY RAND()";
when i fetch the result of $query_1 and $query_2, some of matches with the other. what i need is to make all of the returned values of $query_1 different from the returned values of $query_2.
for example
$query_1 returns
2,5,4,3,7
$query_2 should return
1,6,10,8,9
thanks guys~ more power!
-
Dec 11, 2008, 18:22 #2
PHP and Mysql Random
Hi
just wanted to know the solution for this problem. this has been bugging me for days!!
not really sure if this is a php thing or mysql thing and sorry in advance if i posted this in the wrong channel.
well here it goes...
say i have 2 mysql queries
$query_1 = "SELECT * FROM `table` ORDER BY RAND()";
$query_2 = "SELECT * FROM `table` ORDER BY RAND()";
when i fetch the result of $query_1 and $query_2, some of matches with the other. what i need is to make all of the returned values of $query_1 different from the returned values of $query_2.
for example
$query_1 returns
2,5,4,3,7
$query_2 should return
1,6,10,8,9
thanks guys~ more power!
-
Dec 11, 2008, 19:04 #3
- Join Date
- Jul 2008
- Location
- sudo rm -rf /
- Posts
- 386
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I don't think this will be possible without checking the rows.
-
Dec 11, 2008, 19:10 #4
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
Since both queries will return all the results just in different orders there will be no entries in one not in the other.
If you want to split the entries into two lists with half randomly selected for each list then retrieve them using one select and then use PHP to add alternate entries to two different arrays.Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
Dec 11, 2008, 19:29 #5
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
Bookmarks