View Full Version : While... loop troubles
oracleguy
01-09-2003, 06:40 AM
I'm getting this error:
Parse error: parse error, unexpected $ in C:\Websites\PHP\Poll\poll.inc on line 86
I've tracked the problem to:
while (list ($key, $val) = each ($opts)) {
Now I just started learning PHP so I'm like a total noob.
Line 86 is just:
} ?>
So what's wrong with that while statement?
$opts is an array thats loaded from a database like such:
$i=0;
while ($row = mysql_fetch_assoc($options))
{
If ($row['ID']==1)
{
//Title
$Title=$row['option'];
}
else
{
$opts[$i]=$row['option'];
$i++;
}
}
Thanks in advance.
mordred
01-09-2003, 08:05 AM
"If" in lowercase perhaps, like "if"?
oracleguy
01-10-2003, 01:11 AM
Nope... didn't fix it.
Here is the full page code:
<?PHP
// Connect to database first
# Database Host
$host = "0000";
# MySQL Username
$usr = "0000";
# MySQL Password
$pwd = "0000";
$cid = mysql_connect($host,$usr,$pwd);
mysql_select_db('test1') or die(mysql_error());
$sql = "SELECT * FROM poll_options ORDER BY ID;";
$options = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
$sql = "SELECT * FROM poll_data;";
$polldata = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
//Load the options up
$i=0;
while ($row = mysql_fetch_assoc($options))
{
if ($row['ID']==1)
{
//Title
$Title=$row['option'];
}
else
{
$opts[$i]=$row['option'];
$i++;
}
}
//Load the current data up
$p=0;
$totals=0;
while ($row = mysql_fetch_assoc($polldata))
{
$votes[$row['optionID']]=$row['votes'];
$p++;
$totals=$totals+$row['votes'];
}
?>
<? //HTML CODE STARTS HERE ?>
<table border="0">
<tr><td colspan="3" align="center"><? echo $Title ?></td></tr>
<?PHP
$AlreadyVoted=0;
if ($AlreadyVoted!="1")
{
//THEY HAVENT VOTED YET
?>
<form action="addvote.php" method="post">
<tr>
<?PHP
$y=0;
while (list ($key, $val) = each ($opts)) {
{
if ($y==2)
{
$y=0;
echo '</tr><tr>';
}
else
{
$y++;
}
?>
<td><option name="addValue" value="<? echo $val ?>" /><? echo $val ?></td>
<? } ?>
</tr>
<tr><td colspan="3"><input type="submit" value="Vote" /></td></tr>
</form>
<?
} ?>
mordred
01-10-2003, 12:52 PM
$y=0;
while (list ($key, $val) = each ($opts)) {
{
if ($y==2)
There are two brackets between the while condition and the beginning of the if statement. But not in your first example?
oracleguy
01-10-2003, 04:36 PM
That must be it, I'll try that when i get home.
Dunno why it isn't there in the first example.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.