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");
?>
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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.