jamesxg1 Posted August 13, 2010 Share Posted August 13, 2010 Hiya peeps, I have a mysql database with a record of all the images a customer uploads on my site, these images are displayed on there account. I can get this to work but the problem I'm facing is I need a minimum of 5 images displayed so if they only upload 2 images for instance I need to detect that and add my "No Image Uploaded" image. But if they have uploaded 5 or more I need to just let them be displayed without adding the "No Image Uploaded" picture. Does anyone have any ideas as I'm very stuck! Many thanks James. Quote Link to comment Share on other sites More sharing options...
jamesxg1 Posted August 13, 2010 Author Share Posted August 13, 2010 This is the code I use for each image that a customer has uploaded. $image_return .= '<div class="image"><a title="' . $image['caption'] . '" class="background_light border_medium" onmouseover="this.className=\'background_lightest border_light\'" onmouseout="this.className=\'background_light border_medium\'" href="#"><img src="' . $image['name'] . '" alt="image" width="94" height="94" /></a></div>'; And this for the any that they haven't (giving that they have uploaded less than 5 images). $image_return .= '<div class="image"><a title="' . $image['caption'] . '" class="background_light border_medium" onmouseover="this.className=\'background_lightest border_light\'" onmouseout="this.className=\'background_light border_medium\'" href="#"><img src="noimage.jpg" alt="image" width="94" height="94" /></a></div>'; Many thanks, James. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 13, 2010 Share Posted August 13, 2010 Post your existing code. You should only need to make a few modifications. Quote Link to comment Share on other sites More sharing options...
jamesxg1 Posted August 13, 2010 Author Share Posted August 13, 2010 Ok here's the code I have so far. function images() { $get_images = "SELECT * FROM `images` WHERE `pid` = '$this->pid'"; $run_get_images = mysql_query($get_images); if($run_get_images) { $image_num = mysql_num_rows($run_get_images); if($image_num >= 5) { while($image = mysql_fetch_assoc($run_get_images)) { $image_return .= '<div class="image"><a title="' . $image['caption'] . '" class="background_light border_medium" onmouseover="this.className=\'background_lightest border_light\'" onmouseout="this.className=\'background_light border_medium\'" href=""><img src="' . $image['name'] . '" alt="image" width="94" height="94" /></a></div>'; } } elseif($image_num < 5) { $real_amount = 5; $needed = $real_amount - $image_num; for($i=1; $i == $needed; $i++) { $image_return .= '<div class="image"><a title="' . $image['caption'] . '" class="background_light border_medium" onmouseover="this.className=\'background_lightest border_light\'" onmouseout="this.className=\'background_light border_medium\'" href="#"><img src="noimage.jpg" alt="image" width="94" height="94" /></a></div>'; } } return $image_return; } else { return false; } } I have for the for() wrong, as I am not familiar with that function. Many thanks, James. Quote Link to comment Share on other sites More sharing options...
jamesxg1 Posted August 13, 2010 Author Share Posted August 13, 2010 I think I have it working , just checking if this is full-proof LOL. function images() { $get_images = "SELECT * FROM `images` WHERE `pid` = '$this->pid'"; $run_get_images = mysql_query($get_images); if($run_get_images) { $image_num = mysql_num_rows($run_get_images); if($image_num >= 5) { while($image = mysql_fetch_assoc($run_get_images)) { $image_return .= '<div class="image"><a title="' . $image['caption'] . '" class="background_light border_medium" onmouseover="this.className=\'background_lightest border_light\'" onmouseout="this.className=\'background_light border_medium\'" href=""><img src="' . $image['name'] . '" alt="Image." width="94" height="94" /></a></div>'; } } elseif($image_num < 5) { $real_amount = 5; $needed = $real_amount - $image_num; for ($i = 1; $i <= $needed; $i++) { $image_return .= '<div class="image"><a title="No Image Uploaded." class="background_light border_medium" onmouseover="this.className=\'background_lightest border_light\'" onmouseout="this.className=\'background_light border_medium\'" href="#"><img src="noimage.jpg" alt="No Image Uploaded." width="94" height="94" /></a></div>'; } } return $image_return; } else { return false; } } Many thanks, James. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 13, 2010 Share Posted August 13, 2010 Yea, you're sort of right there. You'll want to use the less than or equal to operator (<=) rather than equal to (==) on this line. for($i=1; $i == $needed; $i++) { EDIT: Yup you fixed it Quote Link to comment Share on other sites More sharing options...
jamesxg1 Posted August 13, 2010 Author Share Posted August 13, 2010 Yea, you're sort of right there. You'll want to use the less than or equal to operator (<=) rather than equal to (==) on this line. for($i=1; $i == $needed; $i++) { EDIT: Yup you fixed it Thank you very much for your help wildteen88! Much appreciated! Many thanks, James. Quote Link to comment 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.