Jump to content

Displaying img with text code help


exl08

Recommended Posts

Currently the code i am using is

 

{

 

echo "<a href=\"" . $row["link"] . "\">

<img src=\"" . $row["image"] . "\" border=0 alt=\"" . $row["text"] . "\">

</a>" ;

}

?>

 

currently it just shows image with hyperlink but i am trying to get it to show image with hyperlink then have a break then text another break and then price

 

Table consists of these rows id, link, image, text, price

 

what codes am i missing to get this to work? thanks

Link to comment
https://forums.phpfreaks.com/topic/126538-displaying-img-with-text-code-help/
Share on other sites

Something like this?

FYI, I changed your quotes around, too many "\" make me nervous.

<?php
{
  echo '<a href="'.$row['link'].'"><img src="'.$row['image'].'" border=0 alt="'.$row['text'].'"></a>';
  echo '<br />'.$row['text'];
  echo '<br />'.$row['price'];
}
?>

just another question, i have also got in the code

 

$num_displayed = 2 ;

 

$result = mysql_query ("SELECT * FROM links ORDER BY RAND() LIMIT $num_displayed")

 

i have attached your code and the second image shows but it is on the same line as price for the first record how do i get it to show up next to it so they are side by side. um also with that code you have their what code would it be so the text and price rows can by hyperlinked with the link row and possibly aligned center to the picture?

 

I no big ask but i seriously have tried and tried and used different php programs and cant come up with anything. thanks

 

so far total code i have is

 

<?php

mysql_connect ('localhost', 'link', 'link') ;

mysql_select_db ('link');

 

$num_displayed = 2 ;

 

$result = mysql_query ("SELECT * FROM links ORDER BY RAND() LIMIT $num_displayed");

 

while ($row = mysql_fetch_array($result))

 

{

echo '<a href="'.$row['link'].'"><img src="'.$row['image'].'" border=0 alt="'.$row['text'].'"></a>';

echo '<br />'.$row['text'];

echo '<br />'.$row['price'];

}

?>

Something like this should work.  Also, I won't be doing anymore for you.

 

<?php
mysql_connect('localhost','link','link');
mysql_select_db('link');
  $num_displayed = 2;

$result = mysql_query("SELECT * FROM links ORDER BY RAND() LIMIT $num_displayed");
?>
<html>
<head>
<style type="text/css">
div#imgDisplay {
  position: relative;
}
p.item {
  text-align: center;
  padding: 5px 10px;
  width: 125px; /* YOU SHOULD EDIT ME */
  border: 1px dashed gray;
  font: 10pt 'Courier new';
  float: right;
  margin: 5px;
}
img {display: block; margin: 0 auto; border: 0;}
</style>
</head>

<body>
<div id="imgDisplay">
<!-- YOU SHOULD EDIT  HEIGHT/WIDTH, OR TAKE THEM OUT IF YOUR IMAGES ARE THE SAME HEIGHT -->
<!-- IF IMAGES ARE ALL THE SAME HEIGHT, ONCE THE IMGS OVERFLOW THE EDGE OF THE PAGE, IT WILL MAKE A NEW ROW NICELY-->
<?php
//IF YOUR COLUMNS ARE ORDERED: ID,LINK,IMAGE,TEXT,PRICE, then list will work
// otherwise put the list $vars in for each table column
while (list($id,$link,$image,$text,$price) = mysql_fetch_array($result))
{
  echo '<p class="item">';
  echo '<a href="'.$link.'">';
  echo '<img src="'.$image.'" height="32" width="32" alt="'.$text.'" /></a>';
  echo '<a href="'.$link.'">'.$text.'</a><br /><a href="'.$link.'">'.$price.'</a></p>';
}
?>
<!--<p class="item"><img height="32" width="32" alt="Description" />Description goes here.<br />$4.99</p>-->
</div>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.