Obsolete80 Posted February 3, 2010 Share Posted February 3, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/190783-displaying-results/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 3, 2010 Share Posted February 3, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/190783-displaying-results/#findComment-1006040 Share on other sites More sharing options...
Obsolete80 Posted February 3, 2010 Author Share Posted February 3, 2010 Sorry about that, I didn't explain fully.. I want to display both the image and the other information together within the same piece of code with the image first. Quote Link to comment https://forums.phpfreaks.com/topic/190783-displaying-results/#findComment-1006044 Share on other sites More sharing options...
PFMaBiSmAd Posted February 3, 2010 Share Posted February 3, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/190783-displaying-results/#findComment-1006058 Share on other sites More sharing options...
Obsolete80 Posted February 3, 2010 Author Share Posted February 3, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/190783-displaying-results/#findComment-1006067 Share on other sites More sharing options...
vividona Posted February 3, 2010 Share Posted February 3, 2010 try to think in single quote ' and double one " Quote Link to comment https://forums.phpfreaks.com/topic/190783-displaying-results/#findComment-1006074 Share on other sites More sharing options...
Obsolete80 Posted February 4, 2010 Author Share Posted February 4, 2010 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/>" ;} ?> Quote Link to comment https://forums.phpfreaks.com/topic/190783-displaying-results/#findComment-1006490 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.