I have here html table showing records from database. One of my column is for delete, what I need is if record is exist in both table disable the delete button. Or if record is not exist in table2 enable the delete button. Any help please?
$query1 = $mysqli1->query("select * from code WHERE item LIKE '%$search%' OR item_code LIKE '%$search%' OR cat_code LIKE '%$search%' order by item_code ASC");
$query2 = $mysqli->query("SELECT count(*) FROM app");
while($r = $query1->fetch_assoc()){
echo"<tr>
<td>".$r['item']."</td>
<td>".$r['cat_code']."</td>
<td>".$r['item_code']."</td>";
if($query1 == 0 && $query2 == 0) {
echo "<td><a href='#' id='".$r['id']."' class='del'><img src='../images/del.png' height='10px' width='10px'></a></td>";
} else {
echo "<td><a href='javascript:void(0)'><img src='../images/stop.png' border='0' width='10' height='10' title='Already Add in Purchase Request' style='cursor: not-allowed;'></a></td>";
}
echo"</tr>";
}
echo "</tbody></table>";
Why don't you check with mysqli_num_rows()
. Try to check something like this
mysqli_num_rows($query3)
instead of
if($query3 == 0 && $query2 == 0) {
............
}
Also there is no disabled
property for anchor tag. So better show the anchor tag only when your conditions satisfies. (Here, show the anchor tag only if data doesnot exists in both tables ).
if(mysqli_num_rows($query1) == 0 && mysqli_num_rows($query2) == 0) {
echo "<td><a href='#' id='".$r['id']."' class='del'><img src='../images/del.png' height='10px' width='10px'></a></td>";
}
Note: To "disable" a link, you can remove its href
attribute, or add a click handler that returns false.