iRock Posted December 12, 2007 Share Posted December 12, 2007 Hi, I'm working through a tutorial and I'm getting the following error: "Parse error: syntax error, unexpected T_ECHO in C:\wamp\www\Local Root\Test\dwc.php on line 11" Here is the code: <?php require_once("Connections/connection.php"); // database connection ////////////////////////////////////////////////////////////// $query = sprintf('SELECT * FROM table1'); $result = @mysql_query($query); $row = mysql_fetch_array($result); ///////////////////////////////////////////////////////////// do ( echo $row{'field3'}."<br>"; )while ($row = mysql_fetch_array($result)) ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> </body> </html> I can't find what I've done wrong, but something tells me that its this part: do ( echo $row{'field3'}."<br>"; )while ($row = mysql_fetch_array($result)) ?> Am I correct? Quote Link to comment Share on other sites More sharing options...
SirChick Posted December 12, 2007 Share Posted December 12, 2007 do ( echo $row{'field3'}."<br>"; )while ($row = mysql_fetch_array($result)) change it to: while ($row = mysql_fetch_array($result)){ echo $row{'field3'}."<br>"; } Quote Link to comment Share on other sites More sharing options...
iRock Posted December 12, 2007 Author Share Posted December 12, 2007 Thanks for the reply. Seems to have done the job. I'm following a video tutorial on Dreamweaverclub.com So, are there rules as to which way and why? Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 12, 2007 Share Posted December 12, 2007 you should be able to do it the original way you had it; you just left off your semi-colon and you used parenthesis and instead of brackets (brackets is what you needed to do a "do while" loop): <?php require_once("Connections/connection.php"); // database connection ////////////////////////////////////////////////////////////// $query = sprintf('SELECT * FROM table1'); $result = @mysql_query($query); $row = mysql_fetch_array($result); ///////////////////////////////////////////////////////////// do { echo $row{'field3'}."<br>"; } while ($row = mysql_fetch_array($result)); ?> Quote Link to comment Share on other sites More sharing options...
SirChick Posted December 12, 2007 Share Posted December 12, 2007 yeah how ever i don't see why people use Do - while when you can just use while =/ Quote Link to comment Share on other sites More sharing options...
SirChick Posted December 12, 2007 Share Posted December 12, 2007 Thanks for the reply. Seems to have done the job. I'm following a video tutorial on Dreamweaverclub.com So, are there rules as to which way and why? The only rule: As long as it works and you make no syntax mistakes your approach to it is not wrong. The big question is... whats the most efficient way...i would say just the while.... rather than do while.. but i dunno for sure its barely worth worry either way. Quote Link to comment Share on other sites More sharing options...
iRock Posted December 12, 2007 Author Share Posted December 12, 2007 Thanks for the help everyone who contributed Quote Link to comment 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.