Well .. there are a few things that I would recommend that you do differently ... just so that things are easier to read. These aren't hard and fast ... just practices that I usually do to keep things readable.
Firstly, try not to use wildcard (*) selects.
Code: Select all
$query = 'Select I_PK, code, ingredientName, measure_unit, units_per_item from tbl_ingredient';
// is a better practice than
$query = 'Select * from tbl_ingredient';
There's a thread around somewhere that indicates that it's faster (especially if you're not pulling all cols), but the main reason I did it this way is because when I'm coding, I can look up to the query and know what columns I am working with.
Then, instead of mysql_fetch_row(), I'd use mysql_fetch_assoc(). That way, you can refer to each piece of data by name instead of index. e.g.
Code: Select all
echo $row['code'];
// instead of
echo $row[1];
To make the button and checkbox ideas work, you need to let each button know which item they belong to. So, the following will get you moving in the right direction.
Code: Select all
<input type=\"checkbox\" name=\"removeid[]\" id=\"checkbox\" value=\"{$row['I_PK']}\" />
But a bigger issue is that you seem to be using individual tables for each row of data. You shouldn't need to do that, so you can just move the open and code table tags outside of the while() loop.
So ...
Code: Select all
echo "<table width=\"720\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"gridData\" onMouseOver=\"this.style.backgroundColor='#EDE6D4'\"; onMouseOut=\"this.style.backgroundColor='transparent'\">";
while($row = mysql_fetch_row($result)){
echo "<tr align = \"center\" class=\"gridRow\">";
// snip
echo "</tr>";
}
echo "</table>";
}
Then the only comment I have to make is that ... well .. I dont know about anyone else, but I never understand why people echo lines of HTML.
Why not ...
Code: Select all
<?php
while($row = mysql_fetch_row($result)) {
?>
<tr align = "center" class="gridRow">
<td width = "70"><input type="checkbox" name="removeid[]" id="checkbox" value="<?php echo $row['I_PK']; ?>" /></td>
</tr>
<?php
}
?>
You don't need to mangle your HTML this way, plus it indents properly when you go into source view. And it's otherwise just far easier to view ... especially if you have an editor with code coloring. The PHP sections just jump right out at you.
Anyhow ... just food for thought.