Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
file name:i.php
table name:emp
database name:hari
PHP
filelds in table:emp_id , first_name , last_name , emp_code , salary , age , date_of_joining , date_of_birth , dept_id , manager_id
<?php

$connection = mysql_connect("192.168.1.7","hari","hari");
mysql_select_db("hari");
 $page_number=$_GET["pagenum"];
$per_page=2;
$result=mysql_query("select * from emp",$connection);
$num_rows=mysql_num_rows($result);
$total_pages=ceil($num_rows/$per_page);
$start=$per_page*($page_number-1);

$res= mysql_query("SELECT * FROM emp limit $start,$per_page");
echo "<a href = 'form.html'>ADD</a>";
echo "<table border=1>";
echo "<tr><th>emp_code</th>
<th>name</th>
<th>dept_id</th>
<th>action</th>
</tr>";

while($rec=mysql_fetch_assoc($res))
    {
        echo "<tr>";
        echo "<td> $rec[emp_code]</td>";
        echo "<td> <a href = 'db.php?emp_id = $rec[emp_id]'>$rec[first_name]</a></td>";
        echo "<td> $rec[dept_id]</td>";
        echo "<td> <a href = 'edit.php?emp_id = $rec[emp_id]'>edit</a>/<a href = 'i.php?emp_code = $rec[emp_code]'>delete</a> </td>";
        echo "</tr>";
   }
echo "</table>";
$a=$_GET["emp_code"];
$del = mysql_query("delete from emp where emp_code='$a' ");
for($i=1;$i<=$total_pages;$i++)
{
if($i==$page_number)
 echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$i'><b>$i</b></a> ";
else
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$i'>$i</a> ";
}

?>
Posted
Updated 10-Oct-11 14:12pm
v3
Comments
Sergey Alexandrovich Kryukov 10-Oct-11 20:13pm    
You certainly know some HTML, so why not formatting your code properly when showing HTML code in HTML?
Please see my fix to you formatting to use it next time.
--SA

If emp_code is non-numeric, you will need apostrophe's in your delete query.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 10-Oct-11 20:14pm    
Good catch, it looks like. My 5.
-SA
Abhinav S 11-Oct-11 0:17am    
Thank you SA.
Hi,

Change your code from

$del = mysql_query("delete from emp where emp_code='$a' ");


to

$del = mysql_query("delete from emp where emp_code='".$a."'");
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900