Jump to content

Tutorial Help - Syntax problems... I think.


iRock

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/81268-tutorial-help-syntax-problems-i-think/
Share on other sites

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

?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.