Page 1 of 1

Displaying hyperlink images

Posted: Wed Feb 25, 2009 12:47 pm
by system5
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi guys, bit of a newbie php person here.

In ASP.NET it was possible to display images that were stored as url's in SQL when displaying the grid view (so I don't need to clog the databases with images). Was wondering if it's also possible with PHP.

Currently using this code to display my grid view.

Code: Select all

<?php
$connection = mysql_connect("localhost", "USER", "PASSWORD") or die("Error connecting to database");
mysql_select_db("DATABASE", $connection);
$result = mysql_query("SELECT * FROM picture ORDER BY pictureId", $connection) or die("error querying database");
$i = 0;
while($result_ar = mysql_fetch_assoc($result)){
?>
<tr <?php if($i%2 == 1){ echo "class='body2'"; }else{echo "class='body1'";}?>>
<td>
<?php echo $result_ar['picname']; ?></td>
<td>
<?php echo $result_ar['url']; ?>
</td>
<?php
$i+=1;
}
?>
If you guys know a much better way of displaying table data, feel free to add as well :P


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Displaying hyperlink images

Posted: Wed Feb 25, 2009 12:50 pm
by pickle
If what you're storing in the database is just a URL, you'll need to put that in an <img> tag for the image to appear.

Re: Displaying hyperlink images

Posted: Wed Feb 25, 2009 1:29 pm
by system5
pickle wrote:If what you're storing in the database is just a URL, you'll need to put that in an <img> tag for the image to appear.
This might sound dumb but where would the image tags go?

Re: Displaying hyperlink images

Posted: Mon Mar 02, 2009 9:53 am
by pickle
Wherever you want the image to appear. Right now you're just outputting the URL in a table cell, use that URL in an image tag.

Re: Displaying hyperlink images

Posted: Mon Mar 02, 2009 3:19 pm
by system5
Heh yeah that was a stupid question. Thanks for your help.