Jump to content

Recommended Posts

Not sure if this should go here or in the mysql section, so I'll apologise in advance if it's wrong

 

I'm currently building a site for a friend with a basic details page to display a selected result from searches. For some reason I can't get a picture and other information to display at the same time.

 

If i use:

while ($row = mysql_fetch_array($query)) {

echo	"<strong>Name: </strong> ".$row['name'].
		"<br/> <strong>Sex: </strong> ".$row['sex'].
		"<br/> <strong>Age: </strong> ".$row['age'].
		"<br/> <strong>Added On: </strong> ".$row['added'].
		"<br/> <strong>Colour: </strong>".$row['colour'].
		"<br/> <strong>Details: </strong>".$row['details'].
		" ";
		"<br/>"
	;}	

 

the information is all displayed.

 

If i use

while ($row = mysql_fetch_array($query)) {
echo 	"<img src='images/pigs/".$row['id'].".jpg' alt='' border='0' class='floatLeft' /> "
	;}	

but for some reason i'm unable to get both to display at the same time.

 

I know this is probably a simple problem to solve, but any help would be appreciated!

Link to comment
https://forums.phpfreaks.com/topic/190783-displaying-results/
Share on other sites

If what you mean is that if you use the second piece of code somewhere on the page after the first piece of code that nothing is retrieved because the while() loop is skipped over, then you need to reset the result pointer to the beginning of the result set - http://php.net/mysql_data_seek

Link to comment
https://forums.phpfreaks.com/topic/190783-displaying-results/#findComment-1006040
Share on other sites

What is the actual code you tried and what was the exact result? Is $row['id'] the base part of the file name? Does the path and file name 'images/pigs/".$row['id'].".jpg' exist relative to the file containing that code?

 

Basically, fill us in on the relevant information that you know about the problem so that someone could actually help you.

Link to comment
https://forums.phpfreaks.com/topic/190783-displaying-results/#findComment-1006058
Share on other sites

The code I have tried is:

while ($row = mysql_fetch_array($query)) {
echo 	"<img src='images/pigs/".$row['id'].".jpg' alt='' border='0' class='floatLeft' /> "
		"<strong>Name: </strong> ".$row['name'].
		"<br/> <strong>Sex: </strong> ".$row['sex'].
		"<br/> <strong>Age: </strong> ".$row['age'].
		"<br/> <strong>Added On: </strong> ".$row['added'].
		"<br/> <strong>Colour: </strong>".$row['colour'].
		"<br/> <strong>Details: </strong>".$row['details'].
		" ";
		"<br/>"
	;}	

 

which just gives me the error "Parse error: parse error, expecting `','' or `';'' in C:\wamp\www\pigs2\details.php on line 38"

 

the code for line 38 is:

"<strong>Name: </strong> ".$row['name'].

 

I've tried several slight variations of the code, but can only seem to get it working when I just use the image OR just the information.

 

I'm not too sure what you mean by

Is $row['id'] the base part of the file name?

 

All of the image files will be named using the id field (primary) in the database, at the moment I only have a small number of records for the building and testing process.

 

Link to comment
https://forums.phpfreaks.com/topic/190783-displaying-results/#findComment-1006067
Share on other sites

I (finally) managed to find the solution... a missing .

 

got the following code to work:

 

while ($row = mysql_fetch_array($query)) {
echo 	"<img src='images/pigs/".$row['id'].".jpg' alt='' border='0' class='floatLeft' />".
		"<strong>Name: </strong> ".$row['name'].
		"<br/><br/> <strong>Sex: </strong> ".$row['sex'].
		"<br/> <strong>Age: </strong> ".$row['age'].
		"<br/> <strong>Added On: </strong> ".$row['added'].
		"<br/> <strong>Colour: </strong>".$row['colour'].
		"<br/><br/> <strong>Details: </strong>".$row['details'].
		" ";
		"<br/>"
	;}	

?> 

Link to comment
https://forums.phpfreaks.com/topic/190783-displaying-results/#findComment-1006490
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.