Pages

Thursday, December 15, 2011

gridview













0 and !is_numeric($start)){
echo "Data Error";
exit;
}


$eu = ($start - 0);
$limit = 10; // No of records to be shown per page.
$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;

$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'name';

$sort_order = 'asc';
if(isset($_GET['sort_by']))
{
if($_GET['sort_by'] == 'asc')
{
$sort_order = 'desc';
} else
{
$sort_order = 'asc';
}
}

switch($sort)
{
case 'name':
$order_by = 'name';
break;
case 'email':
$order_by = 'email';
break;
case 'username':
$order_by = 'username';
break;
case 'company':
$order_by = 'company';
break;
case 'telephone':
$order_by = 'telephone';
break;
case 'post':
$order_by = 'post';
break;
case 'add1':
$order_by = 'add1';
break;
case 'add2':
$order_by = 'add2';
break;
case 'city':
$order_by = 'city';
break;
case 'country':
$order_by = 'country';
break;
}

/////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
$query2=" SELECT * FROM users ORDER BY $sort $sort_order ";
$result2=mysql_query($query2);
echo mysql_error();
$nume=mysql_num_rows($result2);
/////// The variable nume above will store the total number of records in the table////

/////////// Now let us print the table headers ////////////////
echo "










";
////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page///////////
$query=" SELECT * FROM users ORDER BY $sort $sort_order limit $eu, $limit ";
$result=mysql_query($query);
echo mysql_error();

//////////////// Now we will display the returned records in side the rows of the table/////////
while($row = mysql_fetch_array($result))
{


echo "













";

}
echo "
NameEmailUsernameCompanyTelephonePost CodeAddress 1Address 2CityCountry
".$row['name']."".$row['email']."".$row['username']."".$row['company']."".$row['telephone']."".$row['post']."".$row['add1']."".$row['add2']."".$row['city']."".$row['country']."Delete
";
////////////////////////////// End of displaying the table with records ////////////////////////

///////////////////////////////
if($nume > $limit ){ // Let us display bottom links if sufficient records are there for paging

/////////////// Start the bottom links with Prev and next link with page numbers /////////////////
echo "
";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
if($back >=0) {
print "PREV";
}
//////////////// Let us display the page links at center. We will not display the current page as a link ///////////
echo "
";
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $eu){
echo " $l ";
}
else { echo "$l";} /// Current page is not displayed as link and given font color red
$l=$l+1;
}


echo "
";
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $nume) {
print "NEXT";}
echo "
";

}// end of if checking sufficient records are there to display bottom navigational link.
?>

0 comments:

Post a Comment

 
Powered by Blogger