Reputation: 37904
i am going to divide a sql query result into two parts. the reason why i want to do this is that i just want my server handle first only 20 items and then after sleep
the rest part.
how is it possible in sql to part the query into multiple queries after mysql_query
so that i can process the parts separately one after another?
my vision is this:
if(mysql_row_nums($sql)>20){
handle only 20 items
} else {
handle all
}
thanks for reading.
Upvotes: 0
Views: 1591
Reputation: 745
try
if(mysql_num_rows($sql)>20){
$i = 0;
while($result = mysql_fetch_array($sql)){
$i++;
if($i <= 20){
// do some thing with first 20 result
var_dump($result);
}
if($i == 20){
// if we have arrived to result #20 stop excuting script for minute
sleep(60); // 60 = 1 minute ;
}
if($i > 20){
// continue dealing with result after first 20 result.
}
}
}
Upvotes: 1
Reputation: 57322
you can do this by setting limit 0,20
in query
Limit is used to limit your MySQL query results to those that fall within a specified range. You can use it to show the first X number of results, or to show a range from X - Y results.
Upvotes: 2