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 2 of 2

Thread: PHP Paging Help

  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post

    PHP Paging Help

    I have managed to get a paging script working but im having difficult adding a query that output a form to this:

    The paging script is:

    PHP Code:
    <html>
    <head>
    <title>Paging</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <?php
    include("database.php");

    // how many rows to show per page
    $rowsPerPage 3;

    // by default we show first page
    $pageNum 1;

    // if $_GET['page'] defined, use it as page number
    if(isset($_GET['page']))
    {
        
    $pageNum $_GET['page'];
    }

    // counting the offset
    $offset = ($pageNum 1) * $rowsPerPage;

    $query  "SELECT id FROM job LIMIT $offset, $rowsPerPage";
    $result mysql_query($query) or die('Error, query failed');

    // print the random numbers
    while($row mysql_fetch_array($result))
    {
        echo 
    $row['id'] . '<br>';
    }
    echo 
    '<br>';

    // how many rows we have in database
    $query   "SELECT COUNT(id) AS numrows FROM job";
    $result  mysql_query($query) or die('Error, query failed');
    $row     mysql_fetch_array($resultMYSQL_ASSOC);
    $numrows $row['numrows'];

    // how many pages we have when using paging?
    $maxPage ceil($numrows/$rowsPerPage);

    // print the link to access each page
    $self $_SERVER['PHP_SELF'];
    $nav '';
    for(
    $page 1$page <= $maxPage$page++)
    {
        if (
    $page == $pageNum)
        {
            
    $nav .= " $page ";   // no need to create a link to current page
        
    }
        else
        {
            
    $nav .= " <a href=\"$self?page=$page\">$page</a> ";
        }        
    }

    // creating previous and next link
    // plus the link to go straight to
    // the first and last page

    if ($pageNum 1)
    {
        
    $page $pageNum 1;
        
    $prev " <a href=\"$self?page=$page\">[Prev]</a> ";
        
        
    $first " <a href=\"$self?page=1\">[First Page]</a> ";

    else
    {
        
    $prev  '&nbsp;'// we're on page one, don't print previous link
        
    $first '&nbsp;'// nor the first page link
    }

    if (
    $pageNum $maxPage)
    {
        
    $page $pageNum 1;
        
    $next " <a href=\"$self?page=$page\">[Next]</a> ";
        
        
    $last " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";

    else
    {
        
    $next '&nbsp;'// we're on the last page, don't print next link
        
    $last '&nbsp;'// nor the last page link
    }

    // print the navigation link
    echo $first $prev $nav $next $last;

    ?>
    </body>
    </html>
    I want to add the following query and form to this but i unsure how to go about this:

    PHP Code:
    <?php   

    $sessid 
    $_SESSION["username"] ;

    $query "SELECT * FROM job WHERE username='" $sessid"'";


    $result mysql_query($query);
    if(!
    $result){
       
    // check if is something wrong
       
    print "Error";
    }else{
     if(
    mysql_num_rows($result) == 0){  
         print 
    "No Jobs Exist";
     }else{
     while (
    $account = @mysql_fetch_array($result)) {
        
    $username=$account["username"]; 
        
    $id=$account["id"]; 
        
    $jobtitle=$account["jobtitle"]; 
        
    $jobcatergory=$account["jobcatergory"]; 
       
    ?>
    <form class="jobform" action="">  
    <fieldset>  
    <p class="edit"> 
    </fieldset> 
    <fieldset>  
    <label for="jobtitle">Job Title:</label>  
    <input readonly name="jobtitle" type="text" id="jobtitle" value="<?php echo $account["jobtitle"]; ?>" /><br />  
    </fieldset>
    <fieldset style="width: 602; height: 58">  
    <label for="jobcatergory">Job Catergory:</label>  
    <input readonly name="jobcatergory" type="text" id="jobcatergory" value="<?php echo $account["jobcatergory"]; ?>" />  
    </fieldset> 
    <fieldset>  
    <table border="0" align=right width="40%" id="table14">
        <tr>
            <td align="right"><span class="navyboldtxt"><p align="right"><?php echo "<a href='editjob.php?username=$username&id=$id'>Edit/Update Job</a>"?></p></td>
            <td align="right"><span class="navyboldtxt"><p align="right"><?php echo "<a href='deletejob.php?username=$username&id=$id'>Delete Job</a>"?></p></td>
    </td>
        </tr>
    </table>
    </fieldset> 
    </form>  
    <?php
      

     }
    }

    ?>

  • #2
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    Sorted


  •  

    Posting Permissions

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