У меня есть страница index.php, которая выполняет операции CRUD и отображает данные из MySQL с нумерацией страниц. Все работает нормально, кроме ссылок "Редактировать" и "Удалить" в таблице сетки.
Вот код
<?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.= '<a href="?page=1">First</a>';
//if we are not on first page show previous link
if($page!=1) $pagination.='<a href="?page='.$Prev_Page.'"><code><<</code>Previous</a>';
//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) ? ' <strong>'.$x.'</strong>' : ' <a href="?page='.$x.'">'.$x.'</a>' ;
}
//we show next link and last link if user doesn't on last page
if($page!=$pages) $pagination.= ' <a href="?page='.$Next_Page.'">Next>></a>';
if($page!=$pages) $pagination.= ' <a href="?page='.$pages.'">Last</a>';
//display final pagination bar.
?>
<!-- @@@@@@@@@@@@ Grid to show the results fetched from database @@@@@@@@@-->
<table width="70%" border="1">
<tr>
<td align="center">Id</td>
<td align="center">First Name</td>
<td align="center">Last Name</td>
<td align="center">Created</td>
<td align="center">Edit/Delete</td>
</tr>
<?php
//while we going through each row we display info
while($row = mysql_fetch_object($query)){
?>
<tr>
<td align="center"><?php echo $row->id; //row id ?></td>
<td align="center"><?php echo $row->fname; // row first name ?></td>
<td align="center"><?php echo $row->lname; //row las tname ?></td>
<td align="center"><?php echo $row->created; //row created time ?></td>
<td id="action">
<a href="'.$_SERVER['PHP_SELF'].'?action=Edit&pid='.$id.'">
Edit</a> |
<a href="'.$_SERVER['PHP_SELF'].'?action=Delete&pid='.$id.'"
onclick="return confirmToDelete('.$id.');" >Delete</a><br /></td>
</tr>
<?php
}
?>
</table>
<div class="pagination" style="text-align:center"><?php echo $pagination; ?></div>
«редактировать» и «удалить» находятся в отдельных файлах, но эти файлы включены в страницу index.php. Когда редактирование и удаление запускаются отдельно, они работают нормально, но когда я включаю, то в index.php ссылки «Редактировать» и «Удалить " показывать
"Запрошенный '.$_SERVER['PHP_SELF'].' не найдено на этом сервере" ошибка
Что я делаю не так? Пожалуйста, помогите!
Спасибо, Наз.