Results 1 to 7 of 7

Thread: pagination help

  1. #1
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default pagination help

    ok I have got the code on my webpage but the echo is not working or its not displaying the next page or any numbers... this is what i have for the echo numbers..

    PHP Code:
    <?
    include("dbconnect.php");

    $pagenumber 10;
    if(!isset(
    $_GET['cursors'])) {    $page 1;}else {    $page = (int)$_GET['cursors'];}

    $from = (($cursors $pagenumber) - $pagenumber);
    $getnews mysql_query("select * from db ORDER BY id DESC LIMIT $from

    $pagenumber");
    while(
    $r=mysql_fetch_array($getnews)){
    extract($r);
    echo(
    "
    <table width='100%' cellspacing='1' cellpadding='5' bgcolor='#333333' align='center'><tr><td class='title2'><center><font size='4'><a>
    $news</a></font><BR><BR><img style=\"cursor: url('$url')\" src=\"$img\" width=\"100\"><BR>Body<BR><textarea><style><!--BODY{cursor:url(\"$url\");}--></style><a href=\"http://www.xudas.com\"><img src=\"http://www.xudas.com/images/xudasaffy.gif\" border=\"0\"></a></textarea><br><a style=\"cursor: url('$url')\" href=\"#\">Hover over a Link</a><BR><textarea><style>A:hover{cursor: url(\"$url\");}</style>
    <a href=\"http://www.xudas.com\"><img src=\"http://www.xudas.com/images/xudasaffy.gif\" 
    border=\"0\"></a></textarea><br><br></td></tr></table><BR>
    "
    );
    }
    echo 
    "Pages: ";

    $total_results mysql_fetch_array(mysql_query("SELECT COUNT(*) as num FROM db where 

    parentid='0'"
    ));
    $total_pages ceil($total_results['num'] / $pagenumber);
    if (
    $cursors 1) {    $prev = ($cursors 1);    
    echo 
    "$i";
    }for(
    $i 1
    $i <= $total_pages$i++) {    if ($cursors == $i) {        
    echo 
    "<a href=\"index.php?cursors=$i\">$i</a> ";
            }        else {           
    echo 
    "<a href=\"index.php?cursors=$i\">$i</a> ";
            }}
    if (
    $cursors $total_pages) {   
    $next = ($cursors 1);   
    echo 
    "<a href=\"index.php?cursors=$next\"> Older </a>";}

    ?>
    Thats the complete code that I am useing, and I cant figure out why its not paginating it...

    It paginates it but doesn't display the numbers... plz help..

    is there anything wrong with that code...
    Hey new design new look, goto xudas for personal webdsign help.. (:

  2. #2
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    can anyone help me...
    Hey new design new look, goto xudas for personal webdsign help.. (:

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    That code is just plain ugly. Too may line breaks in weird places, tabs are way off, the html output was near unreadable, etc.
    So, I rewrote it in a more standard, possible-to-read format.
    Please, when asking for help, at least make the code decently formatted. And, 3 hours is not long enough to start bumping the thread. You've been here long enough to know that. Bumping like that just annoys me [and others]. I'm not inclined to hurry, then, certainly.
    PHP Code:
    <?php
    include("dbconnect.php");
    $pagenumber 10;
    if(!isset(
    $_GET['cursors'])) {
        
    $page 1;
    }
    else {
        
    $page = (int)$_GET['cursors'];
    }
    $from = (($cursors $pagenumber) - $pagenumber);
    $getnews mysql_query("select * from db ORDER BY id DESC LIMIT $from$pagenumber");
    while(
    $r=mysql_fetch_array($getnews)){
        echo <<<OUT
    <table width="100%" cellspacing="1" cellpadding="5" bgcolor="#333333" align="center">
        <tr>
            <td class="title2">
                <div align="center">
                    <font size="4">
                        <a href="
    {$r['news']}">{$r['news']}</a>
                    </font><BR><BR>
                    <img style="cursor: url('
    {$r['url']}')" src="$img" width="100"><BR>
                    Body<BR>
    <textarea><style>
    <!--BODY{cursor:url("
    {$r['url']}");}-->
    </style>
    <a href="http://www.xudas.com"><img src="http://www.xudas.com/images/xudasaffy.gif" border="0"></a></textarea><br>
    <a style="cursor: url('
    {$r['url']}')" href="#">Hover over a Link</a><BR>
    <textarea><style>
    A:hover{
        cursor: url('
    {$r['url']}');
    }
    </style>
    <a href="http://www.xudas.com"><img src="http://www.xudas.com/images/xudasaffy.gif" border="0"></a></textarea><br><br>
            </td>
        </tr>
    </table><BR>
    OUT;
    }
    echo 
    "Pages: ";
    $total_results mysql_fetch_array(mysql_query("SELECT COUNT(*) as num FROM db where parentid='0'"));
    $total_pages ceil($total_results['num'] / $pagenumber);
    if (
    $cursors 1) {
        
    $prev = ($cursors 1);
        echo 
    "$i";
    }
    for(
    $i 1$i <= $total_pages$i++) {
        if (
    $cursors == $i) {        
            echo 
    "<a href=\"index.php?cursors=$i\">$i</a> ";
        }
        else {           
            echo 
    "<a href=\"index.php?cursors=$i\">$i</a> ";
        }
    }
    if (
    $cursors $total_pages) {   
        
    $next = ($cursors 1);   
        echo 
    "<a href=\"index.php?cursors=$next\"> Older </a>";
    }
    ?>
    The only things I changed:
    1. Formatting.
    2. Removed extract()... bad practice, and can end up doing weird things later on. Very hard to track. Used $r['aaa'] instead.
    3. Used heredoc for the output, and reformatted the html accordingly, as well as formatting the text better for the textareas.
    4. You had some very bizarre tags, mostly <a> tags without any properties, etc. I replaced those with my best guess at what you'd want for values and/or hrefs.
    5. Don't use <center>. Replaced with <div align="center">. Also, you should look into CSS for the page, but I'm not going to get into that now.

    Now.... what's wrong, specifically?

    Do you get an error? What? Which line number?
    If not, you will need to use trial and error to track the data.
    Use echo/print_r() to track data through the script.
    Report the value of the variables/arrays to see where they have the incorrect value.
    A crucial place is the mysql query. You can also echo the query to verify it is correct.
    Last edited by djr33; 10-06-2007 at 04:31 AM.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    im sorry, and I also made the html part (echo) code so no one else would like try thinking about taking it or I don't know why, sorry about that..

    oh sorry about that bumping I won't do it again, im just frustrated with life..

    And the code is amazing how you changed it around. Thankyou..

    but it didn't work for me.. all I got was a blank page..
    Hey new design new look, goto xudas for personal webdsign help.. (:

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I didn't change anything functional on the script. I just made it more readable, so it is possible to fix it.

    As I said, you'll need to do some trial and error output to track the values through the script.

    Be sure error reporting is turned on error_reporting(E_ALL); at the top.

    If you get no errors and no output, then there may be an open loop, but I don't see anything like that. You should just, if it comes down to it, go line by line to output. Even just outputting echo 'test'; will determine where the script fails, then you can figure out how to best fix that.

    These are normal debugging practices and you just need to try them to get used to them. Not difficult, really. Time consuming, if anything.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Oh yay thankyou for helping me out...
    Hey new design new look, goto xudas for personal webdsign help.. (:

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Sure. Once you find the problem area (I can't do that at all since it would require testing line by line--- and it would be a big time commitment), go ahead and post if you aren't sure how to fix it.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •