To make it simple I have table with columns: id | title | image | video where image and video are: name-of-image.jpg/name-of-video.mp4 or NULL. How can I select first 3 rows only containing image and then 1 row containing video and so on, like: 1 image 2 image 3 image 4 video 5 image 6 image 7 image 8 video
I think you'll have to do these separately. How many total rows are we talking about? (I'm thinking you could just fetch all in both categories if it's not too many rows, and parse it in your server-language)
I'm using PHP/MySQL. I need to take max 1000 rows and then just echo rows, my query is: SELECT * FROM `stories` WHERE (`status`='PUBLISHED') AND (`language_id`='3') ORDER BY `date_published` DESC LIMIT 1000 Code (markup): I need to implement what I wrote in my 1st post, to return first 3 rows containing image and next 1 containing video
Can you not handle this in the application? It's irrational and slow to do this in the database but if you have to do it, I think you should be able to with a stored procedure using a loop and a variable that acts as a counter.
2 queries 1 to select the images 1 to select the videos then $vidCounter = 0; $vidMax = count($video); foreach($images as $k => $row){ //echo out the row if ($k %3 == 2 && $k < $vidMax){ //echo out $video[$counter] as a table row $vidCounter++; } } PHP:
I got it, thank you. Since situation is specific and we need some custom implementation and logic I'll have to combine PHP and different MySQL queries