Jump to content

need to display item description with picture


checkmodem12

Recommended Posts

what i'm trying to do is display an item description with corresponding picture. right now i just have this code which displays all the items in "crafts" field. how would i display the picture? would i need to put the pictures in a separate database then call it or some say to just put a link to the picture but i imagine this being difficult if the description loops. please help.


<?
$username="";
$password="";
$database="";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM table WHERE classification='crafts'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$description=mysql_result($result,$i,"description");
$price=mysql_result($result,$i,"price");
$classification=mysql_result($result,$i,"classification");
?>
In your table "table" create a field named "imageurl", this will contain the URL to the picture you wish to display, example: http://www.yoursite.com/images/image.jpg

This should get you going in the right direction...

[code]
<?php
$username="";
$password="";
$database="";

$link = @mysql_connect("localhost", $username, $password); 
if (!$link){
die( "Unable to connect to MySQL Server!");
}

$db_selected = mysql_select_db($database, $link);
if (!$db_selected){
die( "Unable to select database");
}

$result = mysql_query("SELECT * FROM table WHERE classification = 'crafts'");

while($ResultArr = mysql_fetch_array($result)){
$id = $ResultArr['id'];
$description = $ResultArr['description'];
$price = $ResultArr['price'];
$classification = $ResultArr['classification'];
$imageurl = $ResultArr['imageurl'];
echo "<center><img src='". $imageurl ."' alt='". $description ."'><br>". $description ."<br>Price: ". $price ."</center><hr>";
}

mysql_close();
?>
[/code]

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.