Jump to content


Photo

need to display item description with picture


  • Please log in to reply
2 replies to this topic

#1 checkmodem12

checkmodem12
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 11 July 2006 - 01:23 AM

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");
?>

#2 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 11 July 2006 - 02:26 AM

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....mages/image.jpg

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

<?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();
?>


#3 checkmodem12

checkmodem12
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 12 July 2006 - 04:47 AM

thanks that helps a lot. let me try to see how it will look. thanks again.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users