billgod Posted January 25, 2011 Share Posted January 25, 2011 I am creating a site that has to display 36 images on the screen. The image name is stored in the database. My problem is if I have less than 36 images stored I need to display a default image. here is my current query $sql="SELECT col_image, col_url from tbl_images WHERE col_active='1' and col_bigimage='0' ORDER BY RAND() limit 36"; so If I only have 20 active images. I need to display 16 default images. I hope this makes sense. Bill Quote Link to comment https://forums.phpfreaks.com/topic/225640-mysql-query-help/ Share on other sites More sharing options...
Roman Fedorov Posted January 25, 2011 Share Posted January 25, 2011 keep a counter with the number of images you have wrote. Once you finished writing database images, continue writing default images until the counter is 36 Quote Link to comment https://forums.phpfreaks.com/topic/225640-mysql-query-help/#findComment-1165048 Share on other sites More sharing options...
Maq Posted January 25, 2011 Share Posted January 25, 2011 keep a counter with the number of images you have wrote. Once you finished writing database images, continue writing default images until the counter is 36 You can use mysql_num_rows to find out how many are returned. Quote Link to comment https://forums.phpfreaks.com/topic/225640-mysql-query-help/#findComment-1165050 Share on other sites More sharing options...
billgod Posted January 25, 2011 Author Share Posted January 25, 2011 exactly what I needed.. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/225640-mysql-query-help/#findComment-1165061 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.