Jump to content

unexpected $ error


techiefreak05

Recommended Posts

i just tried the pagination tutorial on phpfreaks.com.. and it doesnt work.. i get a unexpect $ error.. heres the code i have for the pagination:

[code]<table width="150" align="right">
<tr>
<td>
<b> Your Bulletins:</b><br>
<div class="section" width="150" align="right">
<center>
        <h5 class="heading">
            Bulletins    |<a href=postComment.php>Post Bulletin</a>|
        </h5>
</center>
<?php
$user = $_SESSION[username];
$queryF="SELECT * FROM friends WHERE `username` = '$_SESSION[username]' AND `accepted` = 'yes'";
$resultF=mysql_query($queryF);
while($array=mysql_fetch_assoc($resultF)){
$poster=$array['friend'];

$limit = 5;


if(empty($bpage)){    // Checks if the $page variable is empty (not set)
        $bpage = 1;      // If it is empty, we're on page 1
    }

    $limitvalue = $bpage * $limit - ($limit);
    // Ex: (2 * 25) - 25 = 25 <- data starts at 25


$queryB="SELECT count(*) FROM `bulletins` WHERE `from` = '$poster' ORDER by 'id' DESC LIMIT $limitvalue, $limit";

$resultB=mysql_query($queryB);

$totalrows = mysql_num_rows($resultB); 

    if(mysql_num_rows($resultB) == 0){
        echo("No Bulletins have been posted!");
    }
   
while($row = mysql_fetch_array($resultB)){
if($bpage != 1){
        $pageprev = $bpage--;
        // Fancy way of subtracting 1 from $page
       
        echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> "); 
        /* Tip: It is a good idea NOT to use $PHP_SELF in this link. It may work,
but to be 99.9% sure that it will, be sure to use the actual name of the file
this script will be running on. Also, the  adds a space to the end of
PREV, and gives some room between the numbers. */
    }else{
        echo("PREV".$limit." ");
        // If we're on page 1, PREV is not a link

    $numofpages = $totalrows / $limit;
    /* We divide our total amount of rows (for example 102) by the limit (25). This

will yield 4.08, which we can round down to 4. In the next few lines, we'll
create 4 pages, and then check to see if we have extra rows remaining for a 5th
page. */
   
    for($i = 1; $i <= $numofpages; $i++){
    /* This for loop will add 1 to $i at the end of each pass until $i is greater
than $numofpages (4.08). */
   
        if($i == $bpage){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF&bpage=$i\">$i</a> ");
        }

if(($totalrows % $limit) != 0){
    /* The above statement is the key to knowing if there are remainders, and it's
all because of the %. In PHP, C++, and other languages, the % is known as a
Modulus. It returns the remainder after dividing two numbers. If there is no
remainder, it returns zero. In our example, it will return 0.8 */
   
        if($i == $bpage){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF&bpage=$i\">$i</a> ");
        }
        /* This is the exact statement that turns pages into link form that is used

above */
    }  // Ends the if statement
   


    if(($totalrows - ($limit * $bpage)) > 0){
    /* This statement checks to see if there are more rows remaining, meaning there
are pages in front of the current one. */
   
        $pagenext  = $bpage++;
        // Fancy way of adding 1 to page
       
        echo("<a href=\"$PHP_SELF?bpage=$pagenext\">NEXT".$limit."</a>");
        /* Since there are pages remaining, this outputs NEXT in link form. */
    }else{
        echo("NEXT".$limit);
        /* If we're on the last page possible, NEXT will NOT be displayed in link
form. */
    }
   
    mysql_free_result($result);
    /* This line is not required, since MySQL will free the result after all
scripts have finished executing; however, it's a nice little backup. */

echo "<table bgcolor=#99CCFF width=200><tr bgcolor=#548099><td height=28><b><font color=white>From: <a href='getInfo.php?user=" . $row['from'] . "'>" . $row['from'] . "</a></b><br><b>Date: </b>" .$row['date'];
echo "</b></font></td></tr></table>";
echo "<table bgcolor=#99CCFF width=200><tr bgcolor=#356B8B><td height=25><center><a href=\"showBulletin.php?id=".$row['id']."\">Subject:  ".$row['subject']."</a></center>";
  echo "</td></tr></table><hr>";
}
}
?>
</div>
</td>
</tr>
</table>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.