SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pagination problem help me.

    Hello I need help. the red line is creating a error:

    Parse error: syntax error, unexpected '}' in C:\wamp\www\aa\test6.php

    I m not sure wats the prob. any1 can help me?

    <?php
    include "dbconnect.php";
    $link=dbconnect();
    $pc = '';

    if (isset($_POST['pc']))
    {
    $pc = $_POST['pc'];
    }
    else {
    if (isset($_GET['pc']))
    {
    $pc = $_GET['pc'];
    }
    }
    if (isset($_GET['pc'])) { $pc = $_GET['pc']; }}if (isset($_GET['pagenum'] && ((int)$_GET['pagenum'] > 0))
    {
    $pagenum = (int)$_GET['pagenum'];
    }
    else {
    $pagenum = 1;
    }

    $query=("select *from doctors WHERE pc='$pc'") or die(mysql_error());
    $resultt=mysql_query($query);
    $rows = mysql_num_rows($resultt);
    if(!$rows) { echo"<script>alert (\"Sorry No Record Found!!!\");history.go(-1)</script>";
    break;
    }
    else {
    $page_rows = 3;
    $last = ceil($rows/$page_rows);
    if ($pagenum < 1)
    {
    $pagenum = 1;
    }
    elseif ($pagenum > $last)
    {
    $pagenum = $last;
    }
    $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
    $result=mysql_query("select *from doctors WHERE pc='$pc' $max;") or die(mysql_error());
    while ($row=mysql_fetch_array($result))
    { echo $row["title"]."&nbsp;"."&nbsp;". $row["name"]; }
    echo " --Page $pagenum of $last-- <p>";
    if ($pagenum != 1)
    {
    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
    echo " ";
    $previous = $pagenum-1;
    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
    }
    echo " ---- ";
    if ($pagenum != $last)
    {
    $next = $pagenum+1;
    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
    echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
    }
    }
    ?>

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2008
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You had two issues:

    Good code:
    Code PHP:
    if (isset($_GET['pc'])) { $pc = $_GET['pc']; }
    if (isset($_GET['pagenum']) && ((int)$_GET['pagenum'] > 0))
    {
    $pagenum = (int)$_GET['pagenum'];
    }

    Your old code:
    Code PHP:
    if (isset($_GET['pc'])) { $pc = $_GET['pc']; }}
    if (isset($_GET['pagenum'] && ((int)$_GET['pagenum'] > 0))
    {
    $pagenum = (int)$_GET['pagenum'];
    }

    Had an extra } on line 1, and missing a closing ) on line 2 for isset function. This is why a good PHP IDE comes in handy, took me two seconds to see the problem when I plugged it in to my application.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kyle W View Post
    You had two issues:

    Good code:
    Code PHP:
    if (isset($_GET['pc'])) { $pc = $_GET['pc']; }
    if (isset($_GET['pagenum']) && ((int)$_GET['pagenum'] > 0))
    {
    $pagenum = (int)$_GET['pagenum'];
    }

    Your old code:
    Code PHP:
    if (isset($_GET['pc'])) { $pc = $_GET['pc']; }}
    if (isset($_GET['pagenum'] && ((int)$_GET['pagenum'] > 0))
    {
    $pagenum = (int)$_GET['pagenum'];
    }

    Had an extra } on line 1, and missing a closing ) on line 2 for isset function. This is why a good PHP IDE comes in handy, took me two seconds to see the problem when I plugged it in to my application.
    Hello I have changed every thing. there is no error now but not retrieving any info from database. just showing a blank page. the code is below. pls help me.

    <?php
    include "dbconnect.php";
    $link=dbconnect();
    $pc = '';

    if (isset($_POST['pc']))
    {
    $pc = $_POST['pc'];
    }
    else {
    if (isset($_GET['pc']))
    {
    $pc = $_GET['pc'];
    }
    if (isset($_GET['pagenum']) && ((int)$_GET['pagenum'] > 0))
    {
    $pagenum = (int)$_GET['pagenum'];
    }
    else {
    $pagenum = 1;
    }

    $query=("select *from doctors WHERE pc='$pc'") or die(mysql_error());
    $resultt=mysql_query($query);
    $rows = mysql_num_rows($resultt);
    if(!$rows)
    {
    echo"<script>alert (\"Sorry No Record Found!!!\");history.go(-1)</script>";
    break;
    }
    else {
    $page_rows = 3;
    $last = ceil($rows/$page_rows);
    if ($pagenum < 1)
    {
    $pagenum = 1;
    }
    elseif ($pagenum > $last)
    {
    $pagenum = $last;
    }
    $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
    $result=mysql_query("select *from doctors WHERE pc='$pc' $max;") or die(mysql_error());
    while ($row=mysql_fetch_array($result))
    { echo $row["title"]."&nbsp;"."&nbsp;". $row["name"]; }
    echo " --Page $pagenum of $last-- <p>";
    if ($pagenum != 1)
    {
    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
    echo " ";
    $previous = $pagenum-1;
    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
    }
    echo " ---- ";
    if ($pagenum != $last)
    {
    $next = $pagenum+1;
    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
    echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
    }
    }
    }
    ?>

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2008
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like your variables aren't being set for the query...

    To test queries, you have to make sure the variables are being set, try echoing $pc and exit(); before the query and see what happens...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •