Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-13-2007, 03:05 AM   PM User | #1
nurvirus
New Coder

 
Join Date: Jul 2007
Location: malaysia
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
nurvirus is an unknown quantity at this point
Paging did not work. please help.

hi folks, i hve a little problem here..i'm doing paging.. at first it is fine. It shows all the data from db.. but then my supervisor ask to to follow her coding. After making few changes here and there.. the data didnt showed anymore... ive attached the image of before and after ive changed few coding.

Before




After




The coding for after changes is made:

PHP Code:
<?php
                    
//connection
                        //include 'library/config.php';
                        //include 'library/opendb.php';
                        
include'fn_database.php';
                        
                    
// how many rows to show per page
                        
$rowsPerPage 5;

                    
// 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 memo_code, memo_date, memo_title, memo_sender FROM memo where id='$memo_code' ";
                        
$pagingQuery "LIMIT $offset, $rowsPerPage";
                        
$result db_query($query $pagingQuery); //or die('Error, query failed');

                     //numbering using loop
                        
$number = (($pageNum 1) * $rowsPerPage) + 1;

                    
// print the memo info in table
                        
echo '<table border="1" width="65%"><tr bordercolor="0" bgcolor="#CCCCCC"><td width="1%" bordercolor="#FFFFFF"><div align="center">NO.</td><td width="3%" bordercolor="#FFFFFF"><div align="center">DATE</td><td width="22%" bordercolor="#FFFFFF"><div align="center">TITLE</td></tr>';
                        while(list(
$memo_code$memo_date$memo_title) = db_array($result))
                            {
                            echo 
"<tr>";
                        
?>

                     <td bordercolor='#FFFFFF' bgcolor='#FFFFCC'><div align="center"><? echo $number ?></td>
                        <td bordercolor='#FFFFFF' bgcolor='#CCCCCC'><div align="center"><? echo $memo_date ?></td>
                        <td bordercolor='#FFFFFF' bgcolor='#FFFFCC'><a href="memo_content.php?id=<?php echo $memo_code?>"><?echo $memo_title;?></td>
                       
                     <?php
                          $number 
++;
                          echo 
"</tr>";
                            }
                             echo 
'</table>';
                          echo 
'<br>';

                    
// how many rows we have in database
                        
$result  db_query($query,"S");//or die('Error, query failed');
                        
$numrows =  $result["count"];

                    
// how many pages we have when using paging?
                        
$maxPage ceil($numrows/$rowsPerPage);
                        
$self $_SERVER['PHP_SELF'];

                    
// creating 'previous' and 'next' link
                    // plus 'first page' and 'last page' link
                    // print 'previous' link only if we're not
                    // on page one
                        
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  '  ';  // we're on page one, don't enable 'previous' link
                        
$first '  '// nor 'first page' link
                        
}

                    
// print 'next' link only if we're not
                    // on the last page
                        
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 '  ';  // we're on the last page, don't enable 'next' link
                        
$last '  '// nor 'last page' link
                            
}

                    
// print the page navigation link
                        
echo $first $prev " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " $next $last;
                        
//include 'library/closedb.php';
                    
?>
                    </form>
And below is the db connection page

PHP Code:
<?
    
function db_connect()
    {
        
$result = @mysql_connect("127.0.0.1""""");

        if (!
$result)
        {
            
$vErrorMessage $vErrorMessage."Unfortunately, we are unable to process your request at this time. We apologize for the inconvenience. Please try again later.<BR>";
            include(
"error.php");
            exit;
        }
           if (!
mysql_select_db("ycl"))
              return 
false;

        return 
$result;
    }

    function 
db_array($pResult)
    {
        
$aResult = array();

        for (
$count=0$row= @mysql_fetch_array($pResult); $count++)
            
$aResult[$count] = $row;

        return 
$aResult;
    }

    function 
db_query($pString$pMode='M')
    {
        
// connect to database
        
$conn db_connect();
        if (!
$conn)     // database connection error"
            
return 0;

        
// check if the user and password is valid
        
$result mysql_query($pString);

        if (!
$result)
            return 
0;

        if (
mysql_num_rows($result)==0)
            return 
0;

        if (
$pMode == 'S')
        {
            return 
mysql_fetch_array($result);
        }
        else
        {
            
$result db_array($result);
            return 
$result;
        }
    }


    function 
db_action($pString)
    {
        
// connect to database
        
$conn db_connect();
        if (!
$conn)     // database connection error"
            
return 0;

        
// check if the user and password is valid
        
$result mysql_query($pString);

        if (!
$result)
            return 
0;

        return 
1;
    }
?>

Last edited by nurvirus; 07-13-2007 at 03:08 AM..
nurvirus is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:56 AM.


Advertisement
Log in to turn off these ads.