Jump to content

Echo Array Question


jason360
Go to solution Solved by requinix,

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.