Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts

    PHP Pagination not showing CSS styling

    Hey guys, I have a PHP pagination script, but for some reason the while looping part that shows each row doesnt show the css styling I have.

    Here is my code.

    PHP Code:

    <?php


        $tableName
    ="news";        
        
    $targetpage "archive.php";     
        
    $limit 10
        
        
    $query "SELECT COUNT(*) as num FROM $tableName";
        
    $total_pages mysql_fetch_array(mysql_query($query));
        
    $total_pages $total_pages['num'];
        
        
    $stages 3;
        
    $page mysql_escape_string($_GET['page']);
        if(
    $page){
            
    $start = ($page 1) * $limit
        }else{
            
    $start 0;    
            }    
        
        
    // Get page data
        
    $query1 "SELECT * FROM $tableName LIMIT $start, $limit";
        
    $result mysql_query($query1);
        
        
    // Initial page num setup
        
    if ($page == 0){$page 1;}
        
    $prev $page 1;    
        
    $next $page 1;                            
        
    $lastpage ceil($total_pages/$limit);        
        
    $LastPagem1 $lastpage 1;                    
        
        
        
    $paginate '';
        if(
    $lastpage 1)
        {    
        

        
        
            
    $paginate .= "<div class='paginate'>";
            
    // Previous
            
    if ($page 1){
                
    $paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
            }else{
                
    $paginate.= "";    }
                

            
            
    // Pages    
            
    if ($lastpage + ($stages 2))    // Not enough pages to breaking it up
            
    {    
                for (
    $counter 1$counter <= $lastpage$counter++)
                {
                    if (
    $counter == $page){
                        
    $paginate.= "<span class='current'>$counter</span>";
                    }else{
                        
    $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}                    
                }
            }
            elseif(
    $lastpage + ($stages 2))    // Enough pages to hide a few?
            
    {
                
    // Beginning only hide later pages
                
    if($page + ($stages 2))        
                {
                    for (
    $counter 1$counter + ($stages 2); $counter++)
                    {
                        if (
    $counter == $page){
                            
    $paginate.= "<span class='current'>$counter</span>";
                        }else{
                            
    $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}                    
                    }
                    
    $paginate.= "...";
                    
    $paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
                    
    $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";        
                }
                
    // Middle hide some front and some back
                
    elseif($lastpage - ($stages 2) > $page && $page > ($stages 2))
                {
                    
    $paginate.= "<a href='$targetpage?page=1'>1</a>";
                    
    $paginate.= "<a href='$targetpage?page=2'>2</a>";
                    
    $paginate.= "...";
                    for (
    $counter $page $stages$counter <= $page $stages$counter++)
                    {
                        if (
    $counter == $page){
                            
    $paginate.= "<span class='current'>$counter</span>";
                        }else{
                            
    $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}                    
                    }
                    
    $paginate.= "...";
                    
    $paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
                    
    $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";        
                }
                
    // End only hide early pages
                
    else
                {
                    
    $paginate.= "<a href='$targetpage?page=1'>1</a>";
                    
    $paginate.= "<a href='$targetpage?page=2'>2</a>";
                    
    $paginate.= "...";
                    for (
    $counter $lastpage - (+ ($stages 2)); $counter <= $lastpage$counter++)
                    {
                        if (
    $counter == $page){
                            
    $paginate.= "<span class='current'>$counter</span>";
                        }else{
                            
    $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}                    
                    }
                }
            }
                        
                    
    // Next
            
    if ($page $counter 1){ 
                
    $paginate.= "<a href='$targetpage?page=$next'>next</a>";
            }else{
                
    $paginate.= "<span class='disabled'>next</span>";
                }
                
            
    $paginate.= "</div>";        
        
        
    }
     
    //echo $total_pages.' Results';
     // pagination
     
    echo $paginate;
    ?>
                                    <div class="newsBorder">
        <table cellspacing="0" border="0" id="newsList" class="width100">
    <tbody>
    <tr class="row_a">
    <td width="30%" class="1 first" id="titleCat">
    <b>Category</b>
    </td>
    <td width="50%" class="item" id="titleTitle">
    <b>News Item</b>
    </td>
    <td width="20%" align="right" class="date">
    <b>Date</b>
    </td>
    </tr>
                        </tbody>

                        </table>
                        



    <?php 
     

            
    while($row mysql_fetch_array($result))
            {
            
            
    ?>        
    <tr class="pad">

    <td valign="top">
    <a href="list.ws?cat=3&amp;page=1" class="catLink">
    <img alt="" src="http://www.runescape.com/img/news/mini_customer_support.gif">
    <span>Website</span>
    </a>
    </td>

    <td valign='middle'><a href="news.php?newsid=<?php echo $row['newsid'?>" class="titleLink"><?php echo $row['title']; ?> </a></td>

    <td valign="middle" align="right" class="date"><?php echo $row['dtime']; ?></td></tr><br>
                <?php
            
    }
        
    ?>

        </div>
    Here is how it looks right now:


    Here is how I want it to look like.


    Its basically everything inside the while is not formatting.

    I have all the CSS I need so that isnt the problem.

    Thanks for the help ahead of time.
    MY MSN: Sith717@Hotmail.com
    PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
    PM me anytime for HTML, PHP or web design help. I will be glad to help you out.

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,285
    Thanks
    4
    Thanked 201 Times in 198 Posts
    Do you have a link to the page available? Have you looked at the source for the page? Have you run the page through the validator to see if there are any errors that might be contributing to the problem?

    At a glance you are closing your table before you start the while which is likely resulting in the complete lack of formatting.
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    bucket (03-20-2011)

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Thanks mate, I moved my </table> and </tbody> and it worked.

    I am getting one last error:
    PHP Code:
    NoticeUndefined indexpage in C:Program FilesEasyPHP5.2.10wwwyanillearchive.php on line 137 
    By any chance can you help me out?

    Its reffering to this page.

    PHP Code:
        $page mysql_escape_string($_GET['page']); 
    The thing is, when I first load the page, I load it without the ?page=1

    So I want it to automalicaly know its page 1 without the ?page=1
    MY MSN: Sith717@Hotmail.com
    PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
    PM me anytime for HTML, PHP or web design help. I will be glad to help you out.

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,285
    Thanks
    4
    Thanked 201 Times in 198 Posts
    Any time you are going to use a form variable, either POST or GET, check to see if it is set before blindly retrieving or using it.

    PHP Code:
    $page '';
    if (isset(
    $_GET['page'])) {
       
    $page mysql_escape_string($_GET['page']);

    What you default $page to, blank or something else, depends on whether or not the rest of your code depends on it and how it will behave if it is an empty string as I showed above.
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    bucket (03-20-2011)

  • #5
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Works great. Thanks.
    MY MSN: Sith717@Hotmail.com
    PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
    PM me anytime for HTML, PHP or web design help. I will be glad to help you out.

  • #6
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Also, is there another way to ouput the date in a different format, so it doesnt show the time is was submitted, just the date. like a d - y -m. What is the part that shows the time called?
    MY MSN: Sith717@Hotmail.com
    PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
    PM me anytime for HTML, PHP or web design help. I will be glad to help you out.

  • #7
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,285
    Thanks
    4
    Thanked 201 Times in 198 Posts
    The PHP date function provides options to format dates and times in just about any fashion desired.
    Dave .... HostMonster for all of your hosting needs

  • #8
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Thing is, how would i make it echo from the database a certain way? How would I query that so it would reformat it.


    EDIT --------------
    would something like this work?

    PHP Code:
    date('m-d-Y'$row['dtime']); 
    So instead of showing it like this:
    2011-03-19 14:48:43

    It would show as:
    15-Mar-2011
    Last edited by bucket; 03-20-2011 at 05:58 PM. Reason: would something like this work? [PHP]date('m-d-Y', $row['dtime']);[/PHP] So instead of showing it like this: [B]2011-03-19
    MY MSN: Sith717@Hotmail.com
    PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
    PM me anytime for HTML, PHP or web design help. I will be glad to help you out.

  • #9
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,285
    Thanks
    4
    Thanked 201 Times in 198 Posts
    What type of column is dtime and what does it contain? The date function expects a Unix epoch time.
    Dave .... HostMonster for all of your hosting needs

  • #10
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts
    dtime is a regular column, but when I inserted the date into it I used the script NOW()

    And it formatted it like: 2011-03-19 14:48:43
    MY MSN: Sith717@Hotmail.com
    PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
    PM me anytime for HTML, PHP or web design help. I will be glad to help you out.

  • #11
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,285
    Thanks
    4
    Thanked 201 Times in 198 Posts
    Then you'll need to use the strtotime function to convert it before you use date to get it in the format desired.

    PHP Code:
    $date_to_print date('m-d-Y'strtotime($row['dtime'])); 
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    bucket (03-20-2011)

  • #12
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Okay thanks, also is there any way I can abreviate the month word to like 3 letters?
    Like MARCH would be MAR or june would be JUN.
    MY MSN: Sith717@Hotmail.com
    PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
    PM me anytime for HTML, PHP or web design help. I will be glad to help you out.

  • #13
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Yes use M instead.

    Click here for more options.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #14
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,285
    Thanks
    4
    Thanked 201 Times in 198 Posts
    Upper case M gets you the 3 character month abbreviation. From the manual for the date function:

    M A short textual representation of a month, three letters Jan through Dec
    Dave .... HostMonster for all of your hosting needs


  •  

    Posting Permissions

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