Page 1 of 1

problem in indexing

Posted: Mon Jan 03, 2005 5:28 am
by itsmani1
hi there....
in the following code i m fetching records and showing them. with limit = 20
problem is that if records that are found are more than 20 it says to view next go to next page but it donot show them on the next page.

Code: Select all

<?php

 $page=$_REQUEST["page"];
  $limit =20;
  $qry = "SELECT * FROM tbl_app"; 
  $res = mysql_db_query($db,$qry,$cid);
  $cnt = mysql_num_rows($res);
  if( (!isset($_POST['regional'])) and (!isset($_POST['discipline'])) and (!isset($_POST['university'])) ){
  echo "Make selection to see Reports";
  exit;
  }

	$strqr = "select 
				a.appid, a.appdate, a.surname, a.flag, a.title, a.forename 
			from 
				tbl_app a, 
				tbl_course c, 
				tbl_app_course ac 
			where 
				a.appid = ac.appid and  
				c.courseid = ac.courseid and ";


$regional = 0;
if(isset($_POST['regional'])){
$regional = $_POST['regional'];

}
$discipline = 0;
if(isset($_POST['discipline'])){
$discipline = $_POST['discipline'];

}
$university = 0;
if(isset($_POST['university'])){
$university = $_POST['university'];

}
if($regional != 0){
	$strqr .= " a.region = $regional and ";
	}
if($discipline != 0){
	$strqr .= " c.disciplineid = $discipline and ";
	}
if($university != 0){
	$strqr .= " c.universityid = $university and ";
	}

  if(isset($_GET['from'])):
   $Rdat = $_GET['from'];
  else:
   if(isset($_POST['month'])):
	$month=$_POST["month"];
   else:
	$month=1;
   endif;
   if(isset($_POST['day'])):
	$day=$_POST["day"];
   else:
	$day=1;
   endif;
   if(isset($_POST['year'])):
	$year=$_POST["year"];
   else:
	$year=1996;
   endif;
   $datef = $day."/".$month."/".$year;
   $Rdat = $year."/".$month."/".$day;
  endif;
  $today = getdate();
  if(isset($_GET['to'])):
   $Rdatto = $_GET['to'];
  else:
   if(isset($_POST['monthto'])):
	$monthto=$_POST["monthto"];
   else:
	$monthto=date("m",time()); 
   endif;
   if(isset($_POST['dayto'])):
	$dayto=$_POST["dayto"];
   else:
	$dayto=$today['mday'];
   endif;
   if(isset($_POST['yearto'])):
	$yearto=$_POST["yearto"];
   else:
	$yearto=$today['year'];
   endif;
   $Rdatto = $yearto."/".$monthto."/".$dayto;
   $datet = $dayto."/".$monthto."/".$yearto;
  endif;
  
if(($discipline == 0 ) && ($university == 0) && ($regional == 0)){
    $strqr = "select 
				a.appid, 
				a.title, 
				a.surname, 
				a.flag, 
				a.surname, 
				a.forename, 
				a.appdate 
			from 			
				tbl_app a 
			where ";
}
if(($discipline != 0) && ($university == 0) && ($regional == 0)){
    $strqr="select 
				a.appid, 
				a.title, 
				a.surname, 
				a.flag, 
				a.surname, 
				a.forename, 
				a.appdate 
			from 			
				tbl_app a 
			where 
				a.region = $discipline and ";
}
if(($discipline == 0) && ($university != 0) && ($regional == 0)){
    $strqr="select 
				a.appid, 
				a.title, 
				a.surname, 
				a.flag, 
				a.surname, 
				a.forename, 
				a.appdate 
			from 			
				tbl_app a, 
				tbl_app_couse ac, 
				tbl_course c 
			where 
				a.appid = ac.appid and 
				ac.courseid = c.courseid and 
				c.universityid = $university and ";
}

if(($discipline == 0) && ($university == 0) && ($regional != 0)){
    $strqr="select 
				a.appid, 
				a.title, 
				a.surname, 
				a.flag, 
				a.surname, 
				a.forename, 
				a.appdate 
			from 			
				tbl_app a 

			where 
				a.region = $regional and ";
}


$strqr.=" a.appdate between $Rdat and $Rdatto order by a.appdate";
$temp = $strqr;
$re = mysql_query($temp);
$nu = mysql_num_rows($re);

  $pager  = Pager::getPagerData($nu, $limit, $page);
  $offset = $pager->offset;
  $limit  = $pager->limit;
  $page   = $pager->page;
  $totalpages= $pager->numPages;


$temp = $strqr;
$strqr.=" DESC LIMIT $offset, $limit";

  $resReport = mysql_db_query($db,$strqr,$cid) or die(mysql_error());
  $cntReport = mysql_num_rows($resReport);


  if($regional == 0):
   $RName = "All regions";
  else:
   $result=mysql_query("SELECT Rname FROM tbl_region WHERE regionID='".$regional."'");
   if(!mysql_num_rows($result)):
    $RName = "Unknown region";
   else:
    $row=mysql_fetch_array($result);
    $RName = stripslashes($row["Rname"]);
   endif;
  endif;

?> <span class="ContentHdr">View Reports (Region: 
<?=$RName?>
;Dates from <?=$datef?>
 to 
<?=$datet?>
)</span><br>
				  
<table cellspacing=2 cellpadding=4 border=0 width="90%" align="left">
  <?
				  if($cntReport > 0){
				  ?>
  <tr> 
    <td width="8%" class="ColumnHdr" bgcolor="#556FB1"><b>ID</b></td>
    <td width="25%" class="ColumnHdr" bgcolor="#556FB1"><b>Date</b></td>
    <td width="50%" class="ColumnHdr" bgcolor="#556FB1"><b>Applicant</b></td>
    <td width="17%" class="ColumnHdr" bgcolor="#556FB1" align="center">&nbsp;</td>
  </tr>
  <?
		  		  $bgColor="DBE5FF";
				    while ($rowReport = mysql_fetch_object($resReport)) {
			  		  $Rid =stripslashes($rowReport->appid);
			  		  $Rdate =stripslashes($rowReport->appdate);
			  		  $Rapp = stripslashes($rowReport->title)." ".stripslashes($rowReport->forename)." ".stripslashes($rowReport->surname);
					  $bgColor=($bgColor=="DBE5FF")?("FFFFFF"): ("DBE5FF");
					  $resume="&nbsp;";
					  switch($rowReport->flag):
						case 1:  $resume="<img src=images/flag.jpg border=0>"; break;
						case 0:  $resume=""; break;
					  endswitch;
					  
		  		  ?>
  <tr bgcolor="#<?=$bgColor?>"> 
    <?PHP
						$y = substr($Rdate,0,4);
						$m = substr($Rdate,5,-12);
						$d = substr($Rdate,8,-9);
//						$t1 = substr($Rdate,12,15) 2004-12-24 04:43:37
						$date = $d.$m.$y;
					?>
    <td class="TableTxt"> 
      <?=$Rid?>
    </td>
    <td class="TableTxt"><? echo $d."-".$m."-".$y; ?></td>
    <td class="TableTxt"><a href="<?=$_SERVER['PHP_SELF']?>?PgAction=EditReport&Section=Report&ShowReport=<?=$Rid?>"> 
      <?=$Rapp?>
      </a></td>
    <td class="TableTxt" align="center" valign="middle"> 
      <?=$resume?>
    </td>
  </tr>
  <?
			  	      $rowReport_count++;
				    }
					
				
					
				 ?>
  <tr bgcolor="#EAEAEA"> 
    <td class="TableTxt" colspan="3">Displaying Page <? echo $page; ?> of Total 
      <? echo $totalpages; ?> Pages<BR>
      Pages: 
      <?

              if ($page != 1)
			    {
                  echo "<a href="adminhome.php?PgAction=ViewReport&Section=Report&page=" . ($page - 1) . ""> Previous </a>";
				 }


			    for ($i = $page; $i <=($page+5); $i++) {
                  if ($i <= $totalpages) {
                      if ($i != 1 )
    				      echo " | ";
				  if ($i == $pager->page)
                    echo "$i";
                    else
                     echo "<a href="adminhome.php?PgAction=ViewReport&Section=Report&page=$i"> $i</a>";

				   }
                    }

			   if ($page != $totalpages)
			   {
                 echo " | ";
				 echo "<a href="adminhome.php?PgAction=ViewReport&Section=Report&page=" . ($page + 1) . ""> Next </a>";
				}
				

             ?>
    </td>
    <TD><?PHP echo "<a href="createadminrep1.php?Pgs=$temp&des=admin"><div align="center"><img src="images/excel.jpg" width="32" height="32" border="0"></a>"; ?> 
       
      </div>
      <div align="center"></div>
      <div align="center"></div></TD>
  </tr>
  <?

				  }else{
		  		  ?>
  <tr> 
    <td colspan=4 align="center" class="TableTxt">< There are no Reports ></td>
  </tr>
  <? } ?>
</table>

feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Mon Jan 03, 2005 6:59 am
by n00b Saibot
Have ya taken care of pagination in the function Pager::getPagerData($nu, $limit, $page) :?:

Posted: Tue Jan 04, 2005 12:59 am
by itsmani1
pagination ??

what's that?
whole code is inform of U and that's it.

Posted: Tue Jan 04, 2005 1:15 am
by feyd
search :? :evil: [devnet]pagination[/devnet]

Posted: Tue Jan 04, 2005 2:41 am
by itsmani1
oki