Jump to content

trying to write a loop - parse error


jarv

Recommended Posts

I get the error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in D:\mypubspace.com\wwwroot\phpsite\pubs.php on line 95

 

$towns  = "SELECT DISTINCT rsTown, COUNT(PubID) As PubCount FROM pubs GROUP BY rsTown  ORDER BY rsTown ASC";
$townresult = mysql_query($towns) or die(mysql_error().'<br>SQL: ' . $towns);


echo <<<EOF
<form name="form3" method="post" action="">
<select name="menu2" onChange="MM_jumpMenu('parent',this,0)" class="textbox">			
<option value="">Please choose a town!</option>
while($row1 = mysql_fetch_array($townresult)){
<option value="pubs_norm1.asp?rsTown='$row1['RSTOWN'];'">
Pubs and bars in $row1['RSTOWN']; ($row1['RSTOWN']</option>
}
</select>
</form>
EOF;

 

Please help

Link to comment
https://forums.phpfreaks.com/topic/214628-trying-to-write-a-loop-parse-error/
Share on other sites

This is a parse error meaning you did not close a string properly or were missing a ";" from your code.  You will want to write cleaner code so it is easier to debug this little things.  I suggest using a full blow IDE to help you debug things like this.  Alls I did was throw your code into netbeans and it told me where the errors were...I think reformatted your code to be easier on the eyes.

 

echo '<form name="form3" method="post" action="">
<select name="menu2" onChange="MM_jumpMenu(\'parent\',this,0)" class="textbox">			
<option value="">Please choose a town!</option>';
while($row1 = mysql_fetch_array($townresult)){
    echo '<option value="pubs_norm1.asp?rsTown='.$row1['RSTOWN'].'">
        Pubs and bars in '.$row1['RSTOWN'].$row1['RSTOWN'].'</option>';
}
echo '</select></form>';

You have your loop in the middle of a HEREDOC. That's not allowed. You have conflicting quotes.

 

Try something like this:

<?php
echo <<<EOF
<form name="form3" method="post" action="">
<select name="menu2" onChange="MM_jumpMenu('parent',this,0)" class="textbox">			
<option value="">Please choose a town!</option>
EOF;
while($row1 = mysql_fetch_array($townresult)){
   echo '<option value="pubs_norm1.asp?rsTown=' .  $row1['RSTOWN'] . '">';
   echo "Pubs and bars in {$row1['RSTOWN']} ({$row1['RSTOWN']})</option>";
}
echo <<<EOF 
</select>
</form>
EOF;
?>

 

Ken

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.