PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
tsm4781
Forum Commoner
Posts: 38 Joined: Wed Jul 09, 2003 7:17 pm
Post
by tsm4781 » Mon Aug 25, 2003 9:44 pm
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"> </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)){
$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);
$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);
}
?>
</table>
</td>
</tr>
</table>
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Aug 25, 2003 9:53 pm
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
tsm4781
Forum Commoner
Posts: 38 Joined: Wed Jul 09, 2003 7:17 pm
Post
by tsm4781 » Mon Aug 25, 2003 9:56 pm
now it says error at line 13 which is the <?PHP line
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Aug 25, 2003 9:58 pm
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
tsm4781
Forum Commoner
Posts: 38 Joined: Wed Jul 09, 2003 7:17 pm
Post
by tsm4781 » Mon Aug 25, 2003 10:17 pm
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?
tsm4781
Forum Commoner
Posts: 38 Joined: Wed Jul 09, 2003 7:17 pm
Post
by tsm4781 » Mon Aug 25, 2003 10:19 pm
actually.. I just saved it as a regular PHP file and I still receive a parse error at the <?PHP
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Aug 25, 2003 10:50 pm
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