Hello Precious Readers,
I know that i havn't post any thing sience 25th of June
and also know that you are awaiting for some post here :)
BTW i have one php function for Paging, its very easy and very dynamic
<?php
# Pass the simple select query and the maximum results you want
# $qryString = "select * from <table-name>";
# $maxRes = 10;
function paging($qryString, $maxRes){
$TOTAL = ceil((mysql_num_rows(mysql_query($qryString)))/$maxRes);
$paging = "";
$args = explode("&",($_SERVER['argv'][0]));
$fireArgv = "?";
foreach($args as $key => $val){
if(!stristr($val,"page=")){
$fireArgv .= $val;
}
}
if($_GET['page'] > 5){
$start = ($_GET['page'] - 5);
if($start > ($TOTAL - $maxRes)){
$start = (($TOTAL - $maxRes) + 1);
}
}
else{$start = 1;}
$cnt=0;
for($i=$start; $i <= $TOTAL && $cnt <= $maxRes; $i++){
$cnt++;
if($cnt > $maxRes) break;
if($_GET['page'] == $i || (empty($_GET['page']) && $i == 1)){
$paging .= $i." ";
}
else{
$paging .= "<a href='".$fireArgv."&page=".$i."'>".$i."</a>"." ";/**/
}
}
return $paging;
}
?>
You just have to pass simple mySql query like "select * from my table" as a first argument.
and as a second argument, just pass total number you want to display as paging eg "10"
so the function would be paging("select * from myTable", 10);
Make sure that you provide only select query only, not with where, limit, order by, etc etc clause.....
it will work like google paging :), to see its result, start implementing it friends.........
And yes, please don't forget to give comments :)





3 comments:
Hi all,
I am working for a software integrator company. My projects includes working on Java and Ruby on Rails and Ajax. I think Web Services is really cool. We also recently have to now work on REST and they are talking about mashups and Struts. Can anyone tell me if there are some good training or conferences so that me and my team members can get to speed with these technologies. Learning from books is not my cup of tea, even not when I was doing engineering ;)
All the help that group members can provide in this regard is much appreciated.
Thanks,
Vaibhavi
its good to generate page number navigation links... but you probably missed to return limit portion for query to actually trim down the result set?
@ Umair,
Yes Umair, Actually when I Develop this function, I have in mind just build the number string, not about triming the result set
Post a Comment