php output of SQL

Soldato
Joined
1 Dec 2004
Posts
22,869
Location
S.Wales
Ok, right, just jazzing up my search feature for my catalogue, on the main catalogue department's output i have various descriptions of the product followed by an image (the link is stored in a field and called up out the output, this is placed inside img tags.

Im trying to do the same when outputting the search results but for some reason the image dont want to display.

Here is the code im using

Code:
while ($field = mysql_fetch_array($result))
{
echo '<div align="left" class="result">';
	$searchResults = $field['catagory'];
	echo '<b>Catagory: </b>';
	echo $searchResults;
	echo '<br>';
	
	$searchResults = $field['title'];
	echo '<b>Title: </b>';
	echo $searchResults;
	echo '<br>';
		
	$searchResults = $field['certificate'];
	echo '<b>Certificate: </b>';
	echo $searchResults;
	echo '<br>';
		
	$searchResults = $field['price'];
	echo '<b>Price: </b>';
	echo $searchResults;
	echo '<br>';
	

	//IMAGE CODE//
	echo '<img src='.$image.' />';

echo "</div>";
}

as you can see it outputs each field as stated above, but because the user is not searching for the image url, i have just echo'd the image src undeneath the last search result code.

$image is the field with the URL stored for the image, it does work as i have my main catalogue linked up in the same way..

http://www.caldicot-pc-helpdesk.co.uk/fcv/database/index4.php

go on there, select dvd or video on the left, see the output with images showing, then search for comedy in the DVD table, see output with no images.
 
How and Where is $image defined?

I know you said it works on other pages, but that is other pages. Have you Viewed Source of the page to see what the final output is? I'm gonna bet it has <img src="" /> :)

EDIT: Just had a look myself, you are receiving red X's because the img tags do not have " surrounding the url.

The other problem you have, is the same image url is posted for every title.

the problem definately lies with the definition of $image. Should you be using $fields['image'] instead?
 
Last edited:
Dj is right, you want something like:
Code:
//IMAGE CODE//
	echo '<img src=\"'.$field['image']. '\"/>';
You need the image location surrounded by double quotes, and comment out the double quotes with a backslash :) Should give you html of
Code:
<img src="yourimagehere.png"/>
 
The image is repeated because i havnt entered my data into the database yet, this is mearly test data..

Regarding the output of the image, iv tried this

Code:
while ($field = mysql_fetch_array($result))
{


echo '<div align="left" class="result">';
	$searchResults = $field['catagory'];
	echo '<b>Catagory: </b>';
	echo $searchResults;
	echo '<br>';
	
	$searchResults = $field['title'];
	echo '<b>Title: </b>';
	echo $searchResults;
	echo '<br>';
		
	$searchResults = $field['certificate'];
	echo '<b>Certificate: </b>';
	echo $searchResults;
	echo '<br>';
		
	$searchResults = $field['price'];
	echo '<b>Price: </b>';
	echo $searchResults;
	echo '<br>';
	

	//IMAGE CODE//
	$field['image'];
	echo '<img src='.$image.' />';

echo "</div>";
}


?>

no luck
 
so i cant do what i did with the output of the other table? instead of having the url in the img tags, the php pulls the url from the field and displays the url inside the img source using '$image' ?

its abit of a pain doin it that way because i will have to add each individual url in the php code, where as the easier way i can just add the url when im adding the table data.
 
Back
Top Bottom