I have been trying to count the number of rows effected before I delete a record from a table.
I have a module I wrote for PHPNuke located here at my development site.
http://milpacs.3rd-infantry-division.net/modules.php?name=MILPACS&file=award
Before I delete a medal I want to see what soldier (member) was awarded the medal. Before I delete I want to tell the admin how many soldiers will have this record deleted from their record, and for them to confirm delete.
Here is my code.
if ($op == "ConfirmDelMedal") {
$id = intval($_POST['id']);
$result2 = $db->sql_query("DELETE FROM " . $prefix . "_milpacs_awards WHERE award_id ='$id'");
Header("Location: /admin.php?op=milpacs");
die();
} else {
echo "<form name=\"delmedal\" action=\"".$admin_file.".php\" method=\"post\">";
//Count if any soldier has been awarded this medal.
$sql = "SELECT COUNT (*) as numrows FROM " . $prefix . "_milpacs_award_lkup WHERE award_id = '$id'";
$row = $db->sql_query($sql);
$return = $row['numrows'];
//testing echo "How many soldiers $return";
?>
<table border="2" cellpadding="2" align="center" cellspacing="0" style="border-collapse: collapse;" bordercolor="#111111" width="100%">
<tr>
<td colspan=2 align="center" bgcolor= "<?php echo $bgcolor2 ?>">
<b><font class="content">There are <?php echo $return ?> soldiers who have been awarded this medal. Deleting this medal will also erase this record in thier profile!</b>
</td>
</tr>
<tr>
<td colspan=2 align="center" bgcolor= "<?php echo $bgcolor2 ?>">
<b><font class="content">Are you sure you want to delete this record?</font></b>
</td>
</tr>
</table>
<br>
<input type="hidden" name="op" value="ConfirmDelMedal"/>
<input type="hidden" name="id" value="<?php echo $id ?>"/>
<input type="submit" align="center" name="Submit" value="Delete"/>
</form>
Doesn't quite work as desired.