thara Posted June 13, 2012 Share Posted June 13, 2012 hello... everyone.. I have some small problem. It is when Im fetch data from my database and print those in different location. I have a database to store images and it contain many type of images. Eg. gallery image, comments image, ad image and so on. So now I need to get only images which type is 'ad'. Note: A single user can store only 2 images as ad images. That mean there are two ad images to a particular user. It ok for me. I did it like this. $q = "SELECT image_name FROM images WHERE image_type = 'ad' AND user = $id"; $r = mysqli_query( $dbc, $q ); while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC)) { $imageName = $row['image_name']; $imageName; // two images contain in this variable. } My problem is, can anybody say, is there a way to print those 2 images in different location (in different two DIV ) and out of while loop. Eg: <div class="add1"> image1 </div> <div class="add2"> image2 </div> any comments are highly appreciated. thank you. Quote Link to comment Share on other sites More sharing options...
litebearer Posted June 13, 2012 Share Posted June 13, 2012 Presuming each image is in a separate row... $q = "SELECT image_name FROM images WHERE image_type = 'ad' AND user = '$id'"; $r = mysqli_query( $dbc, $q ); while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC)) { $imageName[] = $row['image_name']; } $count = count($imageName); if($count>0) { ?> <div class="add1"><?php echo $imageName[0]; ?></div> <?php } if($count>1) { ?> <div class="add2"><?php echo $imageName[1]; ?></div> <?php } Quote Link to comment Share on other sites More sharing options...
thara Posted June 13, 2012 Author Share Posted June 13, 2012 thanks for your reply... now its works for me. further I would like to know. is there a way to exchange images between 2 div in particular time period and displaying 2 image with changing? any comments are greatly appreciated. thank you. Quote Link to comment Share on other sites More sharing options...
insidus Posted June 13, 2012 Share Posted June 13, 2012 How do you mean two divs in a time period? and image changing? like a slider? or change image on hover? Quote Link to comment Share on other sites More sharing options...
thara Posted June 13, 2012 Author Share Posted June 13, 2012 It mean. I want print above selected 2 images in div with randomly changing. Eg. if div 1 has image1 and div 2 has image2 in particular day and other day I need to change it vise versa Quote Link to comment Share on other sites More sharing options...
litebearer Posted June 13, 2012 Share Posted June 13, 2012 Rough concept div 1 if day value is even display image 1 else display image1 div 2 if day value is odd display image 2 else display image 1 Quote Link to comment Share on other sites More sharing options...
thara Posted June 13, 2012 Author Share Posted June 13, 2012 Yes. I need to display 2 images like this If day is even display image1 in 1st div and image2 in 2nd div..... If day is odd diaplay image1 in 2nd div and image2 in 1st div..... Is there a way to accomplish this task???? any comments are greatly appreciated. Thank You Quote Link to comment Share on other sites More sharing options...
litebearer Posted June 13, 2012 Share Posted June 13, 2012 Some psuedo code... $num = date('d'); if($num&1) { $odd = TRUE; } else { $odd = FALSE; } switch $count case: 2 if $odd display div 1 image 2 display div 2 image 1 else display div1 image 1 display div2 image 2 } case: 1 display div1 image 1 } 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.