Webmaster Sun Login
Not a member yet? Sign up

Display Mysql Tbl Results With Pagination

  • HOME
  • FORUMS
  • BLOGS
  • MARKETPLACE
  • ADVERTISING
  • SPECIAL OFFERS
  • WEB HOSTING
  • QUICK MENU
  • REGISTER HERE - Join us for FREE
Results 1 to 4 of 4
    Stick this thread
  1. #1
    Join Date
    Jun 2017
    Posts
    86
    Thumbs Up/Down
    Received: 0/0
    Given: 22/0
    Thanks
    13
    Thanked 1 Time in 1 Post

    Display Mysql Tbl Results With Pagination

    Php Folks,

    I need to do things in procedural style using mysqli. Have not learnt oop style or pdo yet.

    I am trying to create a pagination page where 10 pages display all records. Records spreadover 10 pages.
    Even though my tbl has records, I get notice that no records exist. No records are being displayed in the html table.
    Why is that ?
    Following is my attempt to show records using PREP STMT procedural style using mysqli.

    PHP Code:
    <?php 

    //Required PHP Files. 
    include 'config.php'
    include 
    'header.php'

    //Check if User is already logged-in or not. Get the login_check() FUNCTION to check. 
    if (login_check() === FALSE

        
    //Redirect User to Log-in Page after 2 secs. 
        
    header("refresh:2; url=login.php"); 
        exit(); 

    else 

        
    //Grab User details from Session Variables and echo them. 
        
    $user $_SESSION["user"]; 
        
        
    $id $_SESSION["id"]; 
        
    $account_activation_status $_SESSION["account_activation_status"]; 
        
    $id_video_verification_status $_SESSION["id_video_verification_status"]; 
        
    $id_video_verification_url $_SESSION["id_video_verification_url"]; 
        
    $sponsor_username $_SESSION["sponsor_username"]; 
        
    $recruits_number $_SESSION["recruits_number"]; 
        
    $on_day_number_on_7_days_wish_list $_SESSION["on_day_number_on_7_days_wish_list"]; 
        
    $primary_website_domain $_SESSION["primary_website_domain"]; 
        
    $primary_website_email $_SESSION["primary_website_email"]; 
        
    $username $_SESSION["username"]; 
        
    $first_name $_SESSION["first_name"]; 
        
    $middle_name $_SESSION["middle_name"]; 
        
    $surname $_SESSION["surname"]; 
        
    $gender $_SESSION["gender"]; 
        
    $date_of_birth $_SESSION["date_of_birth"]; 
        
    $age_range $_SESSION["age_range"]; 
        
    $religion $_SESSION["religion"]; 
        
    $marital_status $_SESSION["marital_status"]; 
        
    $working_status $_SESSION["working_status"]; 
        
    $profession $_SESSION["profession"]; 
        
    $home_town $_SESSION["home_town"]; 
        
    $home_borough $_SESSION["home_borough"]; 
        
    $home_city $_SESSION["home_city"]; 
        
    $home_county $_SESSION["home_county"]; 
        
    $home_region $_SESSION["home_region"]; 
        
    $home_state $_SESSION["home_state"]; 
        
    $home_country $_SESSION["home_country"]; 
        
        
    $recipient_username $user
        
    ?> 
        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional/EN"> 
        <html> 
        <head> 
        <meta content="text/html; charset=ISO-8859-1"  http-equiv="content-type"> 
        <title><?php echo "$site_name $user"?> User's Notices in <?php echo $server_time?> time.</title> 
        </head> 
        <body> 
        <br> 
        <center><span style="font-weight: bold;"><?php echo "$site_name $user"?> User's Notices in <?php echo $server_time?> time.</span></center> 
        <br> 
        <br> 
        <?php 
        $query 
    "SELECT id,date_and_time,recipient_username,sender_username,notice FROM notices WHERE recipient_username = ?"
        
        if (
    $stmt mysqli_prepare($conn,$query)) 
        {     
            
    //Bind Parameter 
            
    mysqli_stmt_bind_param($stmt,'s',$recipient_username);     
            
    //Execute Statement 
            
    mysqli_stmt_execute($stmt);
            
    //$result_1 = mysqli_query($conn,$query); 
            //Bind Result Variables     
            
    $result_1 mysqli_stmt_bind_result($stmt,$id,$date_and_time,$recipient_username,$sender_username,$notice); 
            
    mysqli_stmt_store_result($stmt); 
            
    $rows_num mysqli_stmt_num_rows($stmt);     
            
    printf("Result set has %d rows.\n",$rows_num); 
            
            
    $page_count 10
            
    $page_size ceil($rows_num $page_count); 
            
    //Get the Page Number, Default is 1 (First Page).     
            
    $page_number $_GET["page_number"]; 
            if (
    $page_number == ""$page_number 1
            
    $offset = ($page_number -1) * $page_size
            
            
    $query .= " limit {$offset},{$page_size}";         
            
        
    ?>     
        <table width="1500" border="0" cellpadding="5" cellspacing="2" bgcolor="#666666"> 
        <?php if($rows_num) {?> 
        <tr name="headings"> 
        <td bgcolor="#FFFFFF" name="column-heading_submission-number">Submission Number</td> 
        <td bgcolor="#FFFFFF" name="column-heading_logging-server-date-&-time">Date & Time in <?php echo $server_time ?></td> 
        <td bgcolor="#FFFFFF" name="column-heading_to">To</td> 
        <td bgcolor="#FFFFFF" name="column-heading_from">From</td> 
        <td bgcolor="#FFFFFF" name="column-heading_notice">Notice</td> 
        </tr>     
        <?php while($row mysqli_stmt_fetch($stmt)) 
        { 
            
    ?> 
            <tr name="user-details"> 
            <td bgcolor="#FFFFFF" name="submission-number"><?php echo $row['id']; ?></td> 
            <td bgcolor="#FFFFFF" name="logging-server-date-&-time"><?php echo $row['date_and_time']; ?></td> 
            <td bgcolor="#FFFFFF" name="recipient_username"><?php echo $row['recipient_username']; ?></td> 
            <td bgcolor="#FFFFFF" name="sender_username"><?php echo $row['sender_username']; ?></td> 
            <td bgcolor="#FFFFFF" name="notice"><?php echo $row['notice']; ?></td>  
            </tr> 
            <?php 
        

        
    ?> 
        <tr name="pagination"> 
        <td colspan="10" bgcolor="#FFFFFF"> Result Pages: 
        <?php 
        $rows_num 
    mysqli_stmt_num_rows($stmt); 
        if(
    $rows_num <= $page_size
        { 
            echo 
    "Page 1"
        } 
        else 
        { 
            for(
    $i=1;$i<=$page_count;$i++) 
            echo 
    "<a href=\"{$_SERVER['PHP_SELF']}?page_number={$i}\">{$i}</a>  "
        } 
        
    ?> 
        </td> 
        </tr> 
        <?php 
        

        else 
        { 
            
    ?> 
            <tr> 
            <td bgcolor="FFFFFF">No record found! Try another time.</td> 
            </tr> 
            <?php 
        

        
    ?> 
        </table> 
        <br> 
        <br> 
        <center><span style="font-weight: bold;"><?php echo "$site_name $user"?> User's Notices in <?php echo $server_time?> time.</span></center> 
        <br> 
        <br> 
    </div> 
    <br> 
    </body> 
    </html> 
    <?php 

    //Free Result Set 
    mysqli_stmt_free_result($stmt); 

    //Close Database Connection 
    mysqli_stmt_close($stmt); 
    }
    ?>
    I get echoed:
    **Result set has 0 rows.
    No record found! Try another time.**

    This is false. There are records in the mysql tbl.

    I'd appreciate it if someone can show a code sample by editing my code. Or, if you think there is a simpler way of doing things then be kind enough to show a code sample with comments and I will try learning from it.
    Other future newbies to this thread will also appreciate your hard contribution.

    Thank You!

  2. #2
    Join Date
    May 2016
    Location
    USA
    Posts
    1,568
    Thumbs Up/Down
    Received: 476/1
    Given: 27/1
    Thanks
    13
    Thanked 197 Times in 181 Posts
    There is a much easier way to do this. Use a javascript datatable...

    https://www.datatables.net/

  3. #3
    Join Date
    Jun 2017
    Posts
    86
    Thumbs Up/Down
    Received: 0/0
    Given: 22/0
    Thanks
    13
    Thanked 1 Time in 1 Post
    Thanks but I prefer to use php since I am learning it. Javascript, I don't like and seem to complicated to me.

  4. #4
    Join Date
    May 2016
    Posts
    677
    Thumbs Up/Down
    Received: 72/1
    Given: 782/2
    Thanks
    49
    Thanked 52 Times in 51 Posts
    Why you used this command mysqli_stmt_free_result($stmt);

    while you can easily count records in your table with this command
    Code:
    SELECT COUNT(*) FROM yourTable;
    ?

Newer Threads

  1. hmedia
    Rob Whisonant
    Replies: 2 | Views: 494
    Last post by Rob Whisonant, 03-12-2018, 11:07 PM
  2. sunny_pro
    sunny_pro
    Replies: 1 | Views: 428
    Last post by sunny_pro, 03-14-2018, 04:07 PM
  3. ThomosGrye
    Rob Whisonant
    Replies: 2 | Views: 341
    Last post by Rob Whisonant, 03-13-2018, 09:00 AM
  4. adstar
    Mike001
    Replies: 3 | Views: 524
    Last post by Mike001, 03-14-2018, 11:45 AM
  5. Sans_stokes
    Sans_stokes
    Replies: 0 | Views: 255
    Last post by Sans_stokes, 03-15-2018, 06:43 AM

Older Threads

  1. WebsiteIntegrations
    Want A FREE WHMCS Integration? Find Out How!
    By WebsiteIntegrations in forum Services
    WebsiteIntegrations
    Replies: 0 | Views: 592
    Last post by WebsiteIntegrations, 03-07-2018, 08:33 PM
  2. pijushbanarjee
    paritosh
    Replies: 5 | Views: 889
    Last post by paritosh, 11-16-2018, 04:29 PM
  3. ashish4u
    Killua7
    Replies: 4 | Views: 543
    Last post by Killua7, 03-25-2018, 10:25 AM
  4. Edu-Money
    bijutoha
    Replies: 8 | Views: 616
    Last post by bijutoha, 03-12-2018, 10:13 AM
  5. Rob Whisonant
    Youtube channel tutorials?
    By Rob Whisonant in forum YouTube
    Marc van Leeuwen
    Replies: 3 | Views: 618
    Last post by Marc van Leeuwen, 03-10-2018, 03:06 PM

Latest Threads

  1. JeetWin
    JeetWin
    Replies: 0 | Views: 123
    Last post by JeetWin, Yesterday, 05:50 AM
  2. LollyHair
    DarranD
    Replies: 2 | Views: 68
    Last post by DarranD, Today, 04:02 AM
  3. digitalsamyak
    Rob Whisonant
    Replies: 2 | Views: 37
    Last post by Rob Whisonant, 12-10-2018, 06:25 PM
  4. Nemanja
    robertmeyer
    Replies: 5 | Views: 83
    Last post by robertmeyer, Yesterday, 04:25 PM
  5. Marc van Leeuwen
    Marc van Leeuwen
    Replies: 0 | Views: 43
    Last post by Marc van Leeuwen, 12-10-2018, 03:16 AM

Similar Threads

  1. sunny_pro
    sunny_pro
    Replies: 2 | Views: 403
    Last post by sunny_pro, 03-22-2018, 05:21 PM
  2. NadirAziz
    arronmattwills
    Replies: 1 | Views: 1173
    Last post by arronmattwills, 04-06-2015, 04:18 AM
  3. marco
    marco
    Replies: 11 | Views: 3841
    Last post by marco, 10-04-2014, 06:18 PM
  4. vinpay
    AlexBell
    Replies: 9 | Views: 4732
    Last post by AlexBell, 03-27-2014, 08:36 AM
  5. JerryJo
    JerryJo
    Replies: 2 | Views: 1579
    Last post by JerryJo, 04-23-2013, 02:41 AM

Posting Permissions

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

Internet Marketing Forum

Webmaster Sun is a forum where you’ll find in-depth discussions and resources to help you succeed on the web whether you are new or experienced. You’ll find it all here. With topics ranging from internet marketing, search engine optimization, social networking, make money online, web hosting, affiliate marketing as well as hands-on technical support for web design, programming and more. We are a growing community of like-minded people that is keen to help and support each other with ambitions and online endeavors. Learn and grow, make friends and contacts for life.

Come Hang Out With Us

    Facebook Twitter Webmaster Forum Google+

    Webmaster Sun Logo
Copyright ©2012 - 2018, WebmasterSun.com. All rights reserved. Internet marketing forum for internet marketers, webmasters, web hosting providers, designers and affiliate marketers.

Welcome to Webmaster Sun

The World's Number 1 Webmaster Community, SEO and Marketplace

Log in!

Continue with Facebook
Continue With Email. By signing up you indicate that you have read and agree to the Terms of Service and Privacy Policy.

Sign in Manually

Need an account? Sign up now!