Results 1 to 2 of 2

Thread: Wrong?

  1. #1

    Thread Starter
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909

    Wrong?

    This code is printing the 3 results on the page, but not the $pagesvar which would be used for navigation of the pages. Why won't it show?


    PHP Code:
    <?php
    $connection 
    mysql_connect("localhost","stickman373","******");
    mysql_select_db("stickman373_uk_db");

    $totalquery "SELECT COUNT (title) FROM movie ORDER BY title"
    $totalresult mysql_fetch_row(mysql_query($totalquery)); 
    $total $totalresult[0];   // EDIT! 
    mysql_free_result($totalresult); 

    $perpage 2
    if (!
    $page || !is_numeric($page)) $page=1
    $limit = ($page 1) * $perpage

    $numpages ceil($total $perpage); 
    $prev $page 1
    $next $page 1

    if (
    $numpages 1) { 
          
    $pagesvar ""
          if (
    $page 0$pagesvar .= "<a href='?page=1'><u><<</u></a> &nbsp;&nbsp;"
          if (
    $prev && $prev <= $numpages$pagesvar .= "<a href='?page=$prev'><u><</u></a> &nbsp;&nbsp;"

          for (
    $i=$page-2$i $page$i++) { 
                if (
    $i 0$pagesvar .= "<a href='?page=$i'><u>$i</u></a> &nbsp;&nbsp;"
          } 

          
    $pagesvar .= "<a>$page</a> &nbsp;&nbsp;"

          for (
    $i=$page+1$i <= $page+2$i++) { 
                if (
    $i <= $numpages$pagesvar .= "<a href='?page=$i'><u>$i</u></a> &nbsp;&nbsp;"
          } 

          if (
    $next <= $numpages && $next 0$pagesvar .= "<a href='?page=$next'><u>></u></a> &nbsp;&nbsp;"
          if (
    $page <= $numpages$pagesvar .= "<a href='?page=$numpages'><u>>></u></a> "


    $connection mysql_connect("localhost","stickman373","redman");
    mysql_select_db("stickman373_uk_db");

    $query2 "SELECT title FROM movie ORDER BY title DESC LIMIT $limit,$perpage"
    $result2 mysql_query($query2); 
    while (
    $row mysql_fetch_array($result2)) { 
         echo 
    $row['title'];
    echo 
    $pagesvar


    mysql_free_result($result2); 
    ?>

  2. #2
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    because your code sucks.

    do not code like this

    if (!$page || !is_numeric($page)) $page=1;

    you have no {} in it and that is bad coding.

    the reason you don't $pagesvar variable is because your coding sucks.

    if ($page - 3 > 0) $pagesvar .= "<a href='?page=1'><u><<</u></a> &nbsp;&nbsp;";


    is nothing so $pagesvar is = ""

    don't code like that as it is very bad. I don't cvare if they say it is all rigth. that way sucks and you can't tell what is what. if you are just learning don't code like that.
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

Posting Permissions

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



Click Here to Expand Forum to Full Width