Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //assume we already have a database connection
- $query = "SELECT id
- FROM movies
- WHERE publish = 1
- AND showimage = 1
- ORDER BY date DESC
- LIMIT 6";
- $result = $connection->query($query);
- while ($row = $result->fetch_assoc()) {
- //do some stuff
- }
- // row counter
- $counter = 1;
- // loop through each row
- while($row = $result->fetch_assoc()) {
- // If there is more than one row remaining
- // OR if the current row can be divided by two
- if (($result->num_rows - $counter) > 1 || ($counter % 2)) {
- // result code for even rows
- $counter++;
- } else {
- // break out of the loop
- break;
- }
- }
- $result->num_rows
- $result->num_rows
- SELECT size INTO @count FROM (SELECT COUNT(*) as size FROM (SELECT * FROM table LIMIT 6) l) t;
- SET @count = @count - (@count % 2);
- PREPARE stmt_limit FROM 'SELECT * FROM table LIMIT ?';
- EXECUTE stmt_limit USING @count;
- DEALLOCATE PREPARE stmt_limit;
- while($row1 = $result->fetch_assoc() && $row2 = $result->fetch_assoc()) {
- do_something_with($row1);
- do_something_with($row2);
- }
- do_something_with($row1);
- do_something_with($row2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement