mikefrederick Posted October 4, 2007 Share Posted October 4, 2007 i am trying to make it so that i can upload an image and a title for the image and they will automatically be displayed on a page that will look like this: Image1 Title1 Image 2 Title 2 Image 3 Title 3 etc. Right now I have it so that I upload the title to a database and the image to a folder and I can make it so that the page shows one image and one title but I do not know how to show all images with the appropriate title below each one. help please? this is the code I have that will display one image and title, but when more than one is uploaded it does not work: <img src="featuredimages/<? mysql_select_db($database_localhost, $localhost); $query_Rs = "SELECT * FROM featuredprop order by featurename"; $Rs = mysql_query($query_Rs, $localhost) or die(mysql_error()); $totalRows_Rs = mysql_num_rows($Rs); $OrFileName = $row_Rs['featuredprop']; while ($row_Rs = mysql_fetch_assoc($Rs))echo $row_Rs['featurename'];?>" height="100" width="100" > </div> <? mysql_select_db($database_localhost, $localhost); $query_Rs = "SELECT * FROM featuredprop order by featuredtitle"; $Rs = mysql_query($query_Rs, $localhost) or die(mysql_error()); $totalRows_Rs = mysql_num_rows($Rs); $OrFileName = $row_Rs['featuredprop']; while ($row_Rs = mysql_fetch_assoc($Rs))echo $row_Rs['featuredtitle'];?> Quote Link to comment https://forums.phpfreaks.com/topic/71833-help-displaying-images-verically/ Share on other sites More sharing options...
recklessgeneral Posted October 4, 2007 Share Posted October 4, 2007 Hi, Your while loop needs to wrap the html code for displaying the image and title. You are also running two queries, ordering by different fields. This will have the effect of displaying different titles with the images. <?php mysql_select_db($database_localhost, $localhost); $query_Rs = "SELECT * FROM featuredprop order by featurename"; $Rs = mysql_query($query_Rs, $localhost) or die(mysql_error()); $totalRows_Rs = mysql_num_rows($Rs); while ($row_Rs = mysql_fetch_assoc($Rs)) { echo "<img src=\"featuredimages/" . $row_Rs['featurename'] . "\" height="100" width="100" >"; echo $row_Rs['featuredtitle']; } ?> You'll probably want to play around with formatting, but that should get you all the images and titles on your screen. Cheers, Darren. Quote Link to comment https://forums.phpfreaks.com/topic/71833-help-displaying-images-verically/#findComment-361880 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.