Jump to content

Echo Array Question


jason360

Recommended Posts

Hey guys,

 

I am using a function that echos out 10 images from my database.  I need to have a minimum of 4 echoed images.  Some categories have less than 4 images, so I would like to have a default image(s) echoed out if the database has 4 or less images.

 

Does anyone know how I can do this?

 

Below is the code I am using now to echo out the 10 images.

 

Thanks in advance:

 <?php 
		 
		 	 

                    $query = mysql_query('SELECT image_id FROM images ORDER BY RAND() LIMIT 10');

                    $i = 0;
					
					class myCounter3 implements Countable {
							public function count() {
								static $count = 0;
								return ++$count;
							}
						}
						
						$counter = new myCounter3;

                    while ($row = mysql_fetch_array($query))

                    {

                        if($i % 10 === 0)

                        {


                        }

                        echo	'<img src="http://www.mysite.com/'.$row['image_id'].'.jpg" width="300" height="auto"/>';
								
                        $i++;

                    }

                ?> 
Default Image: <img src="http://www.mysite.com/default.jpg" width="300" height="auto"/>
Link to comment
https://forums.phpfreaks.com/topic/293120-echo-array-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.