Results 1 to 7 of 7

Thread: urgent help reqd

  1. #1
    Join Date
    Mar 2007
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    hi i am displayin records from my mysql database but i want then to be displayed pagewise..can some1 help..please please please..

    my code so far:
    PHP Code:
    <?php 
    include 'db.php';    
            
    $valid false;
                    
    $jobcode=$_POST['jobcode'];
            
    $sql="SELECT job.jobcode,job.subject,job.description,job.opening,job.postdate,job.lastdate,candidate.candidate_id,candidate.firstname,candidate.lastname,candidate.resume FROM candidate,job WHERE candidate.jobcode ='$jobcode' AND job.jobcode='$jobcode'";    
            
    $query mysql_query($sql) or die (mysql_error());
    $count=mysql_num_rows($query);
    if (
    $count>0)
    $valid=true;
    if (
    $valid)
    {
    echo 
    "<table width='95%' border='2' >
    <tr>
    <th>JOB CODE</th>
    <th>JOB SUBJECT</th>
    <th>JOB DESCRIPTION</th>
    <th>NUMBER OF OPENINGS</th>
    <th>POST DATE</th>
    <th>LAST DATE</th>
    <th>CANDIDATE ID</th>
    <th>FIRST NAME</th>
    <th>LAST NAME</th>
    <th>RESUME</th>
    </tr>"
    ;
    while(
    $row mysql_fetch_array($query))
      {
    echo 
    "<tr>";
    echo 
    "<td>" $row['jobcode'] . "</td>";
    echo 
    "<td>" $row['subject'] . "</td>";
    echo 
    "<td>" $row['description'] . "</td>";
    echo 
    "<td>" $row['opening'] . "</td>";
    echo 
    "<td>" .$row['postdate'] . "</td>";
    echo 
    "<td>"  $row['lastdate'] . "</td>";
    echo 
    "<td>" .$row['candidate_id'] . "</td>";
    echo 
    "<td>" $row['firstname'] . "</td>";
    echo 
    "<td>" $row['lastname'] . "</td>";
    echo(
    "<td>");
    echo(
    "<a href='" $row['resume'] .  " ' target = '_blank' >" );
    echo(
    "<br/>" $row['resume'] . "</a>"); 
    echo(
    "</td>");
    echo 
    "</tr>";
      }
      echo 
    "</table>";
      }
    else
             echo 
    "<BR><center> NO PROFILES MATCH THE CRITERIA GIVEN.</CENTER> ";
            
    ?>
    this works fine but not pagewise
    Last edited by tech_support; 05-31-2007 at 07:03 AM.

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Please don't use non-descriptive/meaningless titles.
    Putting urgent in the title won't make time go faster also.
    Last edited by tech_support; 05-31-2007 at 07:01 AM. Reason: Mistake
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Mar 2007
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    sorry abt non descriptive title but thts the only one i cud cm up with and u have "not" told me not to use urgent.i was expecting a reply not this..
    thanks anyways

  4. #4
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Sorry, I got messed up with you and another person

    About your problem... What do you mean by "pagewise"?
    Splitting your query to several pages?
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  5. #5
    Join Date
    Mar 2007
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ya i want to display only 10 records in a single page...

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Maybe doing this manually (if statements) would be the best thing. Trying to apply that to the code supplied and that extremely long MySql query could be hard.
    - Mike

  7. #7
    Join Date
    May 2007
    Location
    Sweden
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post

    Good day, Sukanya.paul!

    I took my time and coded what I think you may want!

    You can edit variable $paginLimit, this tells the function to show, if you are on page 8 of maybe 67 pages, it shows, << Prev - ... 4 5 6 7 8 9 10 11 12 13 ... - Next >>, I also added links to first page and last page for You!

    PHP Code:
    <?php

    // Include DB.php
    include 'db.php';

        function 
    mkPagination($start$max$total$pgLimit)
        {

        GLOBAL 
    $jobcode;

        
    $page_req $_SERVER["SCRIPT_NAME"];

        
    $showPrev false;
        
    $showNext false;

        
    $stringHTML "";

        
    $tPages round$total $max );

            
    // If more then One page!
            
    if( $tPages )
            {

                if( 
    $start $total )
                {
                
    $start $total;
                }

            
    // The current page ...
            
    $cPage = ( floor$start $max ) + );

                if( 
    $cPage )
                {
                
    $cPage 1;
                }
                elseif( 
    $cPage )
                {
                
    $show_prev true;
                }

                if( 
    $cPage $tPages )
                {
                
    $cPage $tPages;
                }

                if( 
    $cPage $tPages )
                {
                
    $show_next true;
                }

                    
    // Show Prev link
                    
    if( $show_prev == true )
                    {
                    
    $prevHTML "<a href=\"" $page_req "?jobcode=" $jobcode "&start=" . ( $cPage $max - ( $max ) ) . "\"><< Prev</a> | ";
                    }

                    
    // Show Next link
                    
    if( $show_next == true )
                    {
                    
    $nextHTML " | <a href=\"" $page_req "?jobcode=" $jobcode "&start=" . ( ( $start $start ) + $max ) . "\">Next >></a>";
                    }

                    if( 
    $tPages )
                    {

                        
    $startLink = ( $cPage $pgLimit );

                            if( 
    $startLink )
                            {
                            
    $startLink 1;
                            }
                            elseif( 
    $startLink $tPages )
                            {
                            
    $startLink = ( $tPages );
                            }

                        
    $stopLink = ( $cPage $pgLimit );

                        if( 
    $stopLink $tPages )
                        {
                        
    $stopLink $tPages;
                        }

                    }
                    else
                    {
                    
    $startLink 1;
                    
    $stopLink $tPages;
                    }

                            if( 
    $startLink )
                            {
                            
    $firstHTML "<a href=\"" $page_req "?jobcode=" $jobcode "&start=0\"><< First page</a> - ";
                            
    $strHTML .= "...";
                            }

                            for( 
    $i $startLink$i < ( $stopLink ); $i++ )
                            {

                                if( 
    $i == $cPage )
                                {
                                
    $strHTML .= " <strong>" $i "</strong> ";
                                }
                                else
                                {
                                
    $strHTML .= " <a href=\"" $page_req "?jobcode=" $jobcode "&start=" . ( ( $i $max ) - $max ) . "\">" $i "</a> ";
                                }

                            }

                            if( 
    $stopLink $tPages )
                            {
                            
    $strHTML .= "...";
                            
    $lastHTML " - <a href=\"" $page_req "?jobcode=" $jobcode "&start=" . ( ( $tPages $max ) - $max ) . "\">Last page >></a>";
                            }

            return 
    $firstHTML $prevHTML $strHTML $nextHTML $lastHTML;
            }

        return 
    "";
        }


        
    // -------------------------------------------------------------------


        // How many pages before and after the current page.
        
    $paginLimit 4;

        
    $jobcode $_REQUEST['jobcode'];

        
    // Start of the SQL-query ...
        
    $start    = ( $_REQUEST['start'] > $_REQUEST['start'] : );
        
    $max    = ( $_REQUEST['max'] < 10 10 $_REQUEST['max'] );
      
        
    $isValid false;


        
    $sql "SELECT 
            job.jobcode, 
            job.subject, 
            job.description, 
            job.opening, 
            job.postdate, 
            job.lastdate, 
            candidate.candidate_id, 
            candidate.firstname, 
            candidate.lastname, 
            candidate.resume 

            FROM 

            candidate, 
            job 

            WHERE 

            candidate.jobcode = '" 
    $jobcode "' 

            AND 

            job.jobcode = '" 
    $jobcode "'";

            
    $query_num mysql_query($sql) or die (mysql_error());

            
    $total mysql_num_rows$query_num );

                if( 
    $total )
                {

                    
    // If ( $start + $max ) is more than $total, $start = ( $total - $max )
                    
    if( ( $start $max ) > $total )
                    {
                    
    $start = ( $total $max );

                        
    // If $start is less then 0, $start = 0
                        
    if( $start )
                        {
                        
    $start 0;
                        }

                    }

                
    $query_fetch mysql_query($sql " LIMIT " $start ", " $max) or die (mysql_error());

                echo 
    "<table width=\"95%\" border=\"2\" >
                    <tr>
                        <th>JOB CODE</th>
                        <th>JOB SUBJECT</th>
                        <th>JOB DESCRIPTION</th>
                        <th>NUMBER OF OPENINGS</th>
                        <th>POST DATE</th>
                        <th>LAST DATE</th>
                        <th>CANDIDATE ID</th>
                        <th>FIRST NAME</th>
                        <th>LAST NAME</th>
                        <th>RESUME</th>
                        </tr>"
    ;

                    while( 
    $row mysql_fetch_array$query_fetch ) )
                    {

                    echo 
    "<tr>";
                        echo 
    "<td>" $row['jobcode'] . "</td>";
                        echo 
    "<td>" $row['subject'] . "</td>";
                        echo 
    "<td>" $row['description'] . "</td>";
                        echo 
    "<td>" $row['opening'] . "</td>";
                        echo 
    "<td>" .$row['postdate'] . "</td>";
                        echo 
    "<td>"  $row['lastdate'] . "</td>";
                        echo 
    "<td>" .$row['candidate_id'] . "</td>";
                        echo 
    "<td>" $row['firstname'] . "</td>";
                        echo 
    "<td>" $row['lastname'] . "</td>";
                        echo(
    "<td>");
                        echo(
    "<a href='" $row['resume'] .  " ' target = '_blank' >" );
                        echo(
    "<br/>" $row['resume'] . "</a>"); 
                        echo(
    "</td>");
                    echo 
    "</tr>";

                    }

                echo 
    "</table>";

                echo 
    "<p>" mkPagination($start$max$total$paginLimit) . "</p>";

                }
                else
                {
                echo 
    "<p align=\"center\">NO PROFILES MATCH THE CRITERIA GIVEN.</p>";
                }      
    ?>
    Tell me if it was as you want it!

    Best regards,
    mbrodin
    Last edited by mbrodin; 06-01-2007 at 11:21 AM. Reason: Added ($start + $max) > $total function

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
  •