jarv Posted September 28, 2010 Share Posted September 28, 2010 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 More sharing options...
s0c0 Posted September 28, 2010 Share Posted September 28, 2010 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>'; Link to comment https://forums.phpfreaks.com/topic/214628-trying-to-write-a-loop-parse-error/#findComment-1116795 Share on other sites More sharing options...
kenrbnsn Posted September 28, 2010 Share Posted September 28, 2010 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 Link to comment https://forums.phpfreaks.com/topic/214628-trying-to-write-a-loop-parse-error/#findComment-1116799 Share on other sites More sharing options...
jarv Posted September 28, 2010 Author Share Posted September 28, 2010 thanks, yes my code was very untidy! Link to comment https://forums.phpfreaks.com/topic/214628-trying-to-write-a-loop-parse-error/#findComment-1116812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.