Reputation: 115
My tabel database looks like this:
id | name | Job
-----------------------------
1 | Andrew | Engineer
2 | Fahmy | Designer
3 | Fitriani | Animator
4 | Karin | Animator
i want to display data editing in my web, as you can see, there are two people with same job there, so if i do this:
$query="select * from tb_employees";
$show=mysql_query($query);
while ($data=mysql_fetch_array($show)){
$id= $data['id'];
echo" <tr>
<td>$data[id_usulan]</td>
<td>$data[name]</td>
<td>$data[job]</td>
<td><a href ='edit.php?id=$id'>Edit</a> | <a href ='del.php?id=$id'>Delete</a></td>
</tr>";
It will display all data in that table.
But what i want to do is to edit data per jobs, like this:
id | Job | Option
---------------------------------------------
1 | Engineer | Edit - Delete
2 | Designer | Edit - Delete
3 | Animator | Edit - Delete
(this is my editing interface, since my reputation is so small, i can't post image of my interface, sorry)
So if i Click edit in Animator, i want it to show per person with Animator job editing like this:
id | Name | Option
---------------------------------------------
1 | Fitriani | Edit - Delete
2 | Karin | Edit - Delete
(this is my editing interface, since my reputation is so small, i can't post image of my interface, sorry)
So if i click edit in Karin, i want it to display Karin data editing interface, i use Mysql for database.
Sorry for my bad language.
Upvotes: 1
Views: 107
Reputation: 2509
Run a query like this
$query="select job from tb_employees";
Than run it like this
if(isset($_GET['id']))
{
$id=$_get['id'];
$sql="select name from tb_employees where job='$id'";
$show= mysql_query($sql);
while($data= mysql_fetch_array($show));
echo $data['name'].'<br/>';
}
Upvotes: 2
Reputation: 1646
You can get data per job by the following query
$query="select * from tb_employees group by job ";
And when you will edit then run another query
$query="select * from tb_employees where job=$data[job] ";
Upvotes: 2