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

?>

Link to comment
Share on other sites

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.

Link to comment
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.