Page 1 of 1

Help with Limit/Parse Error

Posted: Mon Aug 25, 2003 9:44 pm
by tsm4781
Can someone tell me why I might get a parse error at the $limit field?

Code: Select all

<table width="100%" border="0" cellspacing="5" cellpadding="0">

  <tr>

    <td>

      <table width="100%" border="0" cellspacing="2" cellpadding="3" align="center" class="bordercolor">
        <tr> 
          <td colspan="6" class="underline"><font face="Verdana, Arial, Helvetica, sans-serif" size="3"><b>User 
            File Manager:</b></font><font face="Verdana, Arial, Helvetica, sans-serif" size="2">&nbsp;</font></td>
        </tr>
        <?PHP	
			
			include_once("db.inc.php");

			mysql_connect($db_host,$db_user,$db_pass) or DIE("Could not connect to DB Server");
			mysql_select_db("$db_name") or DIE("Could not find DB on Server");
			
			$limit          = 25;                
		    $query_count    = "SELECT count(*) FROM alumni";     
		    $result_count   = mysql_query(SELECT count (*) FROM alumni);     
		    $totalrows      = mysql_num_rows($result_count); 

		    if(empty($page))&#123; 
        	$page = 1; 
		    &#125; 
		
			$limitvalue = $page * $limit - ($limit); 
		    $query  = "SELECT * FROM alumni LIMIT $limitvalue, $limit";         
		    $result = mysql_query($query) or die("Error: " . mysql_error());
		
			if(mysql_num_rows($result) == 0)&#123; 
	        echo("Nothing to Display!"); 
&#125;
			
			$query2 = "SELECT * FROM alumni ORDER BY state, name LIMIT 0, 10";
			$result2 = mysql_query($query2) or die("<strong class=black-large>Whoops! Something wrong happened to the my database! It would be nice if you emailed <a href=mailto:$webmaster>me</a> and told me!</strong>");
				if ($result2) 
				&#123;
					while ($r3 = mysql_fetch_array($result)) 
					&#123;
					extract($r3);
					$id = $r3&#1111;0];
				echo "<tr><td width="2%" bgcolor="#e7e7e7"><b>$id</b></td><td width="25%" bgcolor="#e7e7e7"><b>$name</b></td><td bgcolor="#e7e7e7"><b>$city</b></td><td bgcolor="#e7e7e7"><b>$state</b></td><td width="10%" bgcolor="#e7e7e7"><b>$yearbegin</b></td><td width="10%" bgcolor="#e7e7e7"><b>$yearend</b></td><td width="10%" bgcolor="#e7e7e7"><a href='$PHP_SELF?$sessname=$sessid&action=editfan&id=$id'>|Edit|</a></td><td width="10%" bgcolor="#e7e7e7"><a href='$PHP_SELF?$sessname=$sessid&action=deletefan&id=$id';>|Delete|</a></td></tr>";
					&#125;


    		&#125; 

		    $bgcolor = "#E0E0E0"; // light gray 

		    echo("<table>"); 
     
		    while($row = mysql_fetch_array($result))&#123; 
        	if ($bgcolor == "#E0E0E0")&#123; 
            $bgcolor = "#FFFFFF"; 
	        &#125;else&#123; 
            $bgcolor = "#E0E0E0"; 
    	    &#125; 

    echo("<tr bgcolor=".$bgcolor.">n<td>"); 
    echo($row&#1111;"users"]); 
    echo("</td>n<td>"); 
    echo($row&#1111;"usersID"]); 
    echo("</td>n</tr>"); 
    &#125; 

    echo("</table>"); 

    if($page != 1)&#123; 
        $pageprev = $page--; 
         
        echo("<a href="$PHP_SELF&page=$pageprev">PREV".$limit."</a>&nbsp;"); 
    &#125;else&#123; 
        echo("PREV".$limit."&nbsp;"); 
    &#125; 

    $numofpages = $totalrows / $limit; 
     
    for($i = 1; $i <= $numofpages; $i++)&#123; 
        if($i == $page)&#123; 
            echo($i."&nbsp;"); 
        &#125;else&#123; 
            echo("<a href="$PHP_SELF?page=$i">$i</a>&nbsp;"); 
        &#125; 
    &#125; 


    if(($totalrows % $limit) != 0)&#123; 
        if($i == $page)&#123; 
            echo($i."&nbsp;"); 
        &#125;else&#123; 
            echo("<a href="$PHP_SELF?page=$i">$i</a>&nbsp;"); 
        &#125; 
    &#125; 

    if(($totalrows - ($limit * $page)) > 0)&#123; 
        $pagenext = $page++; 
          
        echo("<a href="$PHP_SELF?page=$pagenext">NEXT".$limit."</a>"); 
    &#125;else&#123; 
        echo("NEXT".$limit); 
    &#125; 

				mysql_free_result($result2);
				&#125;

		  
		  ?>
		  </table>
        
    </td>

  </tr>

</table>

Posted: Mon Aug 25, 2003 9:53 pm
by volka
missing quotes on a string literal.
There is also a mismatch on the last }
so I reformatted your code

Code: Select all

<table width="100%" border="0" cellspacing="5" cellpadding="0">
	<tr>
		<td>
			<table width="100%" border="0" cellspacing="2" cellpadding="3" align="center" class="bordercolor">
				<tr>
					<td colspan="6" class="underline">
						<font face="Verdana, Arial, Helvetica, sans-serif" size="3">
							<b>User File Manager:</b>
						</font>
						<font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font><!-- empty font-element, why? -->
					</td>
				</tr>
<?PHP   
include_once("db.inc.php");
mysql_connect($db_host,$db_user,$db_pass) or DIE("Could not connect to DB Server");
mysql_select_db("$db_name") or DIE("Could not find DB on Server");

$limit          = 25;               
$query_count    = "SELECT count(*) FROM alumni";    
$result_count   = mysql_query('SELECT count (*) FROM alumni');  // fix: quote the string literal
$totalrows      = mysql_num_rows($result_count);

if(empty($page)){
	$page = 1;
}

$limitvalue = $page * $limit - ($limit);
$query  = "SELECT * FROM alumni LIMIT $limitvalue, $limit";        
$result = mysql_query($query) or die("Error: " . mysql_error());

if(mysql_num_rows($result) == 0){
	echo("Nothing to Display!");
}

$query2 = "SELECT * FROM alumni ORDER BY state, name LIMIT 0, 10";
$result2 = mysql_query($query2) or die("<strong class=black-large>Whoops! Something wrong happened to the my database! It would be nice if you emailed <a href=mailto:$webmaster>me</a> and told me!</strong>");
if ($result2)
{
	while ($r3 = mysql_fetch_array($result))
	{
		extract($r3); // why?
		$id = $r3[0];
		echo "<tr><td width="2%" bgcolor="#e7e7e7"><b>$id</b></td><td width="25%" bgcolor="#e7e7e7"><b>$name</b></td><td bgcolor="#e7e7e7"><b>$city</b></td><td bgcolor="#e7e7e7"><b>$state</b></td><td width="10%" bgcolor="#e7e7e7"><b>$yearbegin</b></td><td width="10%" bgcolor="#e7e7e7"><b>$yearend</b></td><td width="10%" bgcolor="#e7e7e7"><a href='$PHP_SELF?$sessname=$sessid&action=editfan&id=$id'>|Edit|</a></td><td width="10%" bgcolor="#e7e7e7"><a href='$PHP_SELF?$sessname=$sessid&action=deletefan&id=$id';>|Delete|</a></td></tr>";
	}
}

$bgcolor = "#E0E0E0"; // light gray
echo("<table>");
while($row = mysql_fetch_array($result)){
	if ($bgcolor == "#E0E0E0"){
		$bgcolor = "#FFFFFF";
	}else{
		$bgcolor = "#E0E0E0";
	}

	echo("<tr bgcolor=".$bgcolor.">n<td>");
	echo($row["users"]);
	echo("</td>n<td>");
	echo($row["usersID"]);
	echo("</td>n</tr>");
}
echo("</table>");

if($page != 1){
	$pageprev = $page--;
	echo("<a href="$PHP_SELF&page=$pageprev">PREV".$limit."</a> ");
}else{
	echo("PREV".$limit." ");
}

$numofpages = $totalrows / $limit;

for($i = 1; $i <= $numofpages; $i++){
	if($i == $page){
		echo($i." ");
	}else{
		echo("<a href="$PHP_SELF?page=$i">$i</a> ");
	}
}


if(($totalrows % $limit) != 0){
	if($i == $page){
		echo($i." ");
	}else{
		echo("<a href="$PHP_SELF?page=$i">$i</a> ");
	}
}

if(($totalrows - ($limit * $page)) > 0){
	$pagenext = $page++;
	echo("<a href="$PHP_SELF?page=$pagenext">NEXT".$limit."</a>");
}else{
	echo("NEXT".$limit);
}

mysql_free_result($result2);
}  // fix: todo: } mismatch

?>
			</table>
		</td>
	</tr>
</table>
should make it easier to spot the error

Posted: Mon Aug 25, 2003 9:56 pm
by tsm4781
now it says error at line 13 which is the <?PHP line

Posted: Mon Aug 25, 2003 9:58 pm
by volka
strange I only get
Errors parsing test.php
PHP Parse error: parse error, unexpected '}' in test.php on line 98
and line 98 is } // fix: todo: } mismatch
marking the line as comment and it gets parsed

Posted: Mon Aug 25, 2003 10:17 pm
by tsm4781
I have a custom build Control Panel which the file I attached includes inside that has a lot of PHP code.. would that have something to do with it?

Posted: Mon Aug 25, 2003 10:19 pm
by tsm4781
actually.. I just saved it as a regular PHP file and I still receive a parse error at the <?PHP

Posted: Mon Aug 25, 2003 10:50 pm
by volka
then take your original code an apply the changes there.
$result_count = mysql_query(SELECT count (*) FROM alumni);

Code: Select all

$result_count   = mysql_query('SELECT count (*) FROM alumni');
mysql_free_result($result2);
}
there's no opening { for that bracket