1,105,288 Community Members

Can someone help me?

Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

i am trying to do a pagination but, i cant seem to get the problem..

<?
//pagination

    $objConnect = mysql_connect("localhost","root","") or die(mysql_error());
    $objDB = mysql_select_db("custech");
    $strSQL = "SELECT * FROM proposals ";
    $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
    $Num_Rows = mysql_num_rows($objQuery);

    $Per_Page = 4;   // Per Page

    $Page = $_GET["Page"];
    if(!$_GET["Page"])
    {
        $Page=1;
    }

    $Prev_Page = $Page-1;
    $Next_Page = $Page+1;

    $Page_Start = (($Per_Page*$Page)-$Per_Page);
    if($Num_Rows<=$Per_Page)
    {
        $Num_Pages =1;
    }
    else if(($Num_Rows % $Per_Page)==0)
    {
        $Num_Pages =($Num_Rows/$Per_Page) ;
    }
    else
    {
        $Num_Pages =($Num_Rows/$Per_Page)+1;
        $Num_Pages = (int)$Num_Pages;
    }

// Before using $_POST['value'] add this - to avoid error on undefined index

if (!isset($_POST['txtSearch']))
{
    //Instruction if $_POST['value']doesnt exist
    $_POST['txtSearch']="%";
}


//to select all record in database and to display all records

 if($levelbox=='')
 {
    $sql="SELECT * FROM proposals ORDER BY pro_id ASC LIMIT $Page_Start , $Per_Page";
 }
 else {
 $strSQL .=" SELECT * FROM proposals WHERE $levelbox LIKE '%".$_POST['txtSearch']."%' ORDER BY pro_id ASC LIMIT $Page_Start , $Per_Page";
    //$sql="SELECT * FROM proposals WHERE $levelbox LIKE '%".$_POST['txtSearch']."%' ORDER BY pro_id ASC";
 }

//$sql="SELECT * FROM robots WHERE $levelbox LIKE '%".$_POST['txtSearch']."%'";

    $objQuery  = mysql_query($strSQL);
//$result=mysql_query($sql);

//error message if query fails

if (!$objQuery)
{
die;
exit;
}

//if no records found

if (mysql_num_rows($objQuery)==0)
{
echo "<table cellspacing='0' cellpading='3'><tr><td>";
echo "No row found, no row to print, so, am exiting";
echo "</td></tr></table>";
exit;
}



    ?>
    <table width="600" border="1">
      <tr>
        <th width="91"> <div align="center">Proposal ID </div></th>
        <th width="98"> <div align="center">Proposal Name </div></th>
        <th width="198"> <div align="center">Company </div></th>
        <th width="97"> <div align="center">Proposl Date </div></th>
        <th width="59"> <div align="center">Proposal Status</div></th>
        <th width="60"> <div align="center">File</div></th>
        <th width="71"> <div align="center">Proposal By</div></th>
      </tr>
    <?
    while($objResult = mysql_fetch_array($objQuery))
    {
    ?>
      <tr>
        <td><div align="center"><?=$objResult["pro_id"];?></div></td>
        <td><?=$objResult["pro_name"];?></td>
        <td><?=$objResult["pro_company"];?></td>
        <td><div align="center"><?=$objResult["pro_date"];?></div></td>
        <td align="right"><?=$objResult["pro_status"];?></td>
        <td align="right"><a href="<?=$objResult["pro_file"];?>">DOWNLOAD</a></td>
        <td align="right"><?=$objResult["pro_by"];?></td>
      </tr>
    <?
    }
    ?>
    </table>

    <br>
    Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
    <?
    if($Prev_Page)
    {
        echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
    }

    for($i=1; $i<=$Num_Pages; $i++){
        if($i != $Page)
        {
            echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
        }
        else
        {
            echo "<b> $i </b>";
        }
    }
    if($Page!=$Num_Pages)
    {
        echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
    }
    mysql_close($objConnect);
//end of pagination
?>
Member Avatar
OsaMasw
Posting Whiz in Training
212 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

I've used this pagination its really easy to customize
http://phpsense.com/2007/php-pagination-script/

LastMitch
Deleted Member
 
4
 

@missy_mi

i am trying to do a pagination but, i cant seem to get the problem..

Deos it show any errors? If yes please post the line.

Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

there just this :

Notice: Undefined index: Page in C:\xampp\htdocs\CDMS\proposals.php on line 302
Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

is this line :

$Per_Page = 4;   // Per Page

    $Page = $_GET["Page"];
    if(!$Page)
    {
        $Page=1;
    }

    $Prev_Page = $Page-1;
    $Next_Page = $Page+1;
Member Avatar
cigoL..:)
Light Poster
47 posts since Jul 2011
Reputation Points: -1 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 2 [?]
 
1
 

try

if (isset($Page)){
       if (!$Page){
           $Page=1;
       }

       // And so on and so forth :)
    }
Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
1
 

In these parts for back, next etc, shouldn't Page be $Page?

echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

no changes guys..sAME RESULT..

LastMitch
Deleted Member
 
6
 

@missy_mi

Notice: Undefined index: Page in C:\xampp\htdocs\CDMS\proposals.php on line 302

Instead of this:

$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;

Try this:

$Page = $_GET["Page"];

if($Page == 0) $Page = 1;
$Prev_Page = $Page - 1;                     
$Next_Page = $Page + 1; 

AndreRet is correct about this query being $Page not $Next_Page:

echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";

It should be $Page not $Next_Page

for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page){
echo "<a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}else{
echo "<b> $i </b>";
}
}
if(!$Page=$Num_Pages){

echo "<a href ='$_SERVER[SCRIPT_NAME]?Page=$Page'>Total Pages</a>";

}else if($Prev_Page){

echo "<a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'>Prev Page</a>";

}else if ($Next_Page{

echo "<a href='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next Page</a>";
}
Member Avatar
diafol
Where are my eyes?
12,943 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,845 [?]
Skill Endorsements: 90 [?]
Moderator
Featured
Sponsor
 
0
 

I think it's due to this:

 $Page = $_GET["Page"];

The only index I can see in the code is the above. It means that the get var hasn't been set yet.

$Page = (isset($_GET["Page"])) ? intval($_GET["Page"]) : 1;

That should safely set your page to the integer value of the get variable if it's set or default to 1.

Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

@diafol & all :

i already change it and there are no more notice that..but, the 1 page shows all the the data i specifically code.. 4 -- $Per_Page = 4; // Per Page ..but it display all.. what do i do??

Member Avatar
diafol
Where are my eyes?
12,943 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,845 [?]
Skill Endorsements: 90 [?]
Moderator
Featured
Sponsor
 
0
 

he 1 page shows all the the data i specifically code.. 4 -- $Per_Page = 4; // Per Page ..but it display all.. what do i do??

Sorry, I don't understand

LastMitch
Deleted Member
 
5
 

@missy_mi

i already change it and there are no more notice that..but, the 1 page shows all the the data i specifically code.. 4 -- $Per_Page = 4; // Per Page ..but it display all.. what do i do??

OK, I'm getting confused too. The issue is that all of the 4 pages appear at once? You want it to display one page at a time?

Can you post your update code so we can see what is the issue?

Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

okayh...the item displayed should have only 4 line of data..e:g

-harry, 12
-sully, 15
-daniel, 12
-maria, 15
-george, 17

other data should not appear in the first page because i applied :

$Per_Page = 4;

but, the resul i got was :

-harry, 12
-sully, 15
-daniel, 12
-maria, 15
-george, 17
-cullen, 11
-sarah, 14
-henry, 13
-michelle, 17

  • it means that all the data is display..instead of just 4 data per page..
    do get what i mean??
LastMitch
Deleted Member
 
6
 

@missy_mi

it means that all the data is display..instead of just 4 data per page..
do get what i mean??

Can you post your update code not the results. Right now, I don't know what is wrong with your code because you mention you made some adjustments.

Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
<?php

//open connection

$connectdb=mysql_connect("localhost","root");
if(!$connectdb)
{
die('Unable to connect to server:'.mysql_error());
exit;
}

//select database

$selectdb=mysql_select_db("custech", $connectdb);
if (!$selectdb)
{
die('Unable to select database custech:'.mysql_error());
exit;
}

if (!isset($_POST['levelbox']))
{
    //Instruction if $_POST['value']doesnt exist
    $_POST['levelbox']="%";
}

$levelbox = ($_POST['levelbox']);

?>

<form method="POST" name="frmSearch" action="<?"proposals.php"?>">
<table width="900" border="0" cellspacing="0" cellpadding="0">

   <td width="70%"><p>
   <select name="levelbox" class="inputbox2">
    <option  value=""/>-- ALL --</option>
    <option  value="pro_name"/>Proposal Name</option>
    <option  value="pro_status" />Status</option>
    <option  value="pro_company" />Company Name</option>
    <option  value="pro_date" />Date</option>
    </select>
    <input name="txtSearch" type="text" id="fullname" size="30" />
        <input type="submit" name="cmdSearch" value="Search">
   </td>
  </tr>


</table> 
</form>


<?
//pagination
    $Per_Page = 4;   // Per Page


    $objConnect = mysql_connect("localhost","root","") or die(mysql_error());
    $objDB = mysql_select_db("custech");
    $strSQL = "SELECT * FROM proposals ORDER BY pro_id ASC ";
    $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
    $Num_Rows = mysql_num_rows($objQuery);

$Per_Page = 4;   // Per Page

        $Page = (isset($_GET["Page"])) ? intval($_GET["Page"]) : 1;
    if(!$Page)
    {
        $Page=1;
    }

    $Prev_Page = $Page-1;
    $Next_Page = $Page+1;

    $Page_Start = (($Per_Page*$Page)-$Per_Page);
    if($Num_Rows<=$Per_Page)
    {
        $Num_Pages =1;
    }
    else if(($Num_Rows % $Per_Page)==0)
    {
        $Num_Pages =($Num_Rows/$Per_Page) ;
    }
    else
    {
        $Num_Pages =($Num_Rows/$Per_Page)+1;
        $Num_Pages = (int)$Num_Pages;
    }

// Before using $_POST['value'] add this - to avoid error on undefined index

if (!isset($_POST['txtSearch']))
{
    //Instruction if $_POST['value']doesnt exist
    $_POST['txtSearch']="%";
}


//to select all record in database and to display all records

 if($levelbox=='')
 {
 $strSQL;
    //$sql="SELECT * FROM proposals ORDER BY pro_id ASC LIMIT $Page_Start , $Per_Page";
 }
 else {
 $strSQL .="WHERE $levelbox LIKE '%".$_POST['txtSearch']."%' ORDER BY pro_id ASC ";
    //$sql="SELECT * FROM proposals WHERE $levelbox LIKE '%".$_POST['txtSearch']."%' ORDER BY pro_id ASC";
 }

//$sql="SELECT * FROM robots WHERE $levelbox LIKE '%".$_POST['txtSearch']."%'";

    $objQuery  = mysql_query($strSQL);
//$result=mysql_query($sql);

//error message if query fails

if (!$objQuery)
{
die;
exit;
}

//if no records found

if (mysql_num_rows($objQuery)==0)
{
echo "<table cellspacing='0' cellpading='3'><tr><td>";
echo "No row found, no row to print, so, am exiting";
echo "</td></tr></table>";
exit;
}



    ?>
    <table width="600" border="1">
      <tr>
        <th width="40"> <div align="center"><font color="blue" size="3">Proposal ID </font></div></th>
        <th width="98"> <div align="center"><font color="blue" size="3">Proposal Name </font></div></th>
        <th width="80"> <div align="center"><font color="blue" size="3">Company </font></div></th>
        <th width="97"> <div align="center"><font color="blue" size="3">Proposal Date </font></div></th>
        <th width="59"> <div align="center"><font color="blue" size="3">Proposal Status</font></div></th>
        <th width="60"> <div align="center"><font color="blue" size="3">File</font></div></th>
        <th width="71"> <div align="center"><font color="blue" size="3">Proposal by </font></div></th>
      </tr>
    <?
    while($objResult = mysql_fetch_array($objQuery))
    {
    ?>
      <tr>
        <td><div align="center"><?=$objResult["pro_id"];?></div></td>
        <td><div align="center"><?=$objResult["pro_name"];?></div></td>
        <td><div align="center"><?=$objResult["pro_company"];?></div></td>
        <td><div align="center"><?=$objResult["pro_date"];?></div></td>
        <td><div align="center"><?=$objResult["pro_status"];?></div></td>
        <td><div align="center"><a href="<?=$objResult["pro_file"];?>">DOWNLOAD</a></div></td>
        <td><div align="center"><?=$objResult["pro_by"];?></div></td>
      </tr>
    <?
    }
    ?>
    </table>

    <br>
    Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
    <?
    if($Prev_Page)
    {
        echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
    }

    for($i=1; $i<=$Num_Pages; $i++){
        if($i != $Page)
        {
            echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
        }
        else
        {
            echo "<b> $i </b>";
        }
    }
    if($Page!=$Num_Pages)
    {
        echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
    }
    mysql_close($objConnect);
//end of pagination
?>
Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
2
 

sorry its a bit messy..still in trial version

LastMitch
Deleted Member
 
6
 

@missy_mi

You have a duplicate of this (it should be one):

$Per_Page = 4; // Per Page

The issue is here:

for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
Member Avatar
missy_mi
Junior Poster in Training
64 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

i dont understand, sir..what seems to be the problem..??

LastMitch
Deleted Member
 
6
 

@missy_mi

i dont understand, sir..what seems to be the problem..??

You have a duplicate line 54 and on line 63:

$Per_Page = 4; // Per Page

The issue is here about echo out more than 4 lines:

for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article