Jump to content

Recommended Posts

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'];?>

Link to comment
https://forums.phpfreaks.com/topic/71833-help-displaying-images-verically/
Share on other sites

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.

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.