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. Link to comment Share on other sites More sharing options...
Larry Posted June 13, 2012 Share Posted June 13, 2012 With the code you have, $imageName will only ever represent one image, specifically the last image returned by the query. So you would need to change that to an array. Then you could refer to $imageName[0] and $imageName[1] in the respective DIVs. Link to comment Share on other sites More sharing options...
thara Posted June 13, 2012 Author Share Posted June 13, 2012 Thank you Mr. Larry for your quick response. Its greatly appreciated. Link to comment Share on other sites More sharing options...
Recommended Posts