Hi
I’ve a page, index.php, which does CRUD operations and displays data from MySQL with pagination. Everything’s working fine except the “Edit” and “Delete” links in the grid table.
Here’s the code
[php]<?php
$connection=mysql_connect(‘localhost’,‘root’,’’) or die(mysql_error());
mysql_select_db(‘test1’,$connection) or die(mysql_error());
//displaying 5 results per page
$per_page = 5;
//number of adjacent links to show left and right of the current page.
$adjacents = 5;
//execute a mysql query to retrieve count of total users in table
$pages_query = mysql_query(“SELECT COUNT(‘id’) FROM users”) or die(mysql_error());
//get total number of pages to be shown from total result
$pages = ceil(mysql_result($pages_query, 0) / $per_page);
//get current page from URL ,if not present set it to 1
$page = (isset($_GET[‘page’])) ? (int)$_GET[‘page’] : 1 ;
//calculate actual start page with respect to Mysql
$start = ($page - 1) * $per_page;
//execute a mysql query to retrieve all result from current page by using LIMIT keyword in mysql
$query = mysql_query(“SELECT * FROM users order by id DESC LIMIT $start, $per_page”) or die(mysql_error());
// @@@@@@@@@@@@@@@@@@@@@ Pagination starts here @@@@@@@@@@@@@@@@@@@@@@@
//store pagination result in a string so that we can place any where in page.
$pagination="";
//if current page is first show first only else reduce 1 by current page
$Prev_Page = ($page==1)?1:$page - 1;
//if current page is last show last only else add 1 to current page
$Next_Page = ($page>=$pages)?$page:$page + 1;
//if we are not on first page show first link
if($page!=1) $pagination.= ‘First’;
//if we are not on first page show previous link
if($page!=1) $pagination.=’<<
Previous’;
//we are going to display 5 links on pagination bar
$numberoflinks=5;
//find the number of links to show on right of current page
$upage=ceil(($page)/$numberoflinks)*$numberoflinks;
//find the number of links to show on left of current page
$lpage=floor(($page)/$numberoflinks)*$numberoflinks;
//if number of links on left of current page are zero we start from 1
$lpage=($lpage==0)?1:$lpage;
//find the number of links to show on right of current page and make sure it must be less than total number of pages
$upage=($lpage==$upage)?$upage+$numberoflinks:$upage;
if($upage>$pages)$upage=($pages-1);
//start building links from left to right of current page
for($x=$lpage; $x<=$upage; $x++){
//if current building link is current page we don’t show link,we show as text else we show as linkn
$pagination.=($x == $page) ? ’ ‘.$x.’’ : ’ ‘.$x.’’ ;
}
//we show next link and last link if user doesn’t on last page
if($page!=$pages) $pagination.= ’ Next>>’;
if($page!=$pages) $pagination.= ’ Last’;
//display final pagination bar.
?>
Id | First Name | Last Name | Created | Edit/Delete |
<?php echo $row->id; //row id ?> | <?php echo $row->fname; // row first name ?> | <?php echo $row->lname; //row las tname ?> | <?php echo $row->created; //row created time ?> |
Edit |
Delete |
“edit” and “delete” is in separate files, but these files are included in index.php page
When edit and delete are run separately they work fine, but when i include then in index.php
the links “Edit” and “Delete” show
“The requested ‘.$_SERVER[‘PHP_SELF’].’ was not found on this server” error
What am I doing wrong? Kindly help!
Thanks
Naz