Reputation: 284
as the title says i am trying to create an increasing numbers array for example:
I have a number 30 and i want to create an array out of it like
$numbers = array(6,12,18,24,30);
// then extract data from mysql
foreach( $numbers as $LIMITNUMBER ){
$query = "SELECT * FROM table WHERE id=id ORDER BY ASC LIMIT 0,".$LIMITNUMBER;
}
The 30 number above could be any number 100 or 200 but it always divides by 6 so the array first value has to be 6 and then +6 addition to the previous value.
Upvotes: 0
Views: 372
Reputation:
The easiest way to do this would be to use a function implementing PHP 'range'.
Here's an example based on your question:
function incrementToMax($max) {
foreach (range(6, $max, 6) as $currentMax) {
$query = "SELECT * FROM table WHERE id=id ORDER BY ASC LIMIT 0,".$currentMax;
}
}
Example usage:
incrementToMax(60);
Upvotes: 1