I'm trying to parse an html table and use the column values to form a mysql query. I'm trying to test to see if my variables are working correctly, but I'm not getting the first alert to pop up. I know that the function is executing because the second alert displays, but I don't know what is wrong with my variables.
Also, how do I get the selected value from the select box?
Here is my function:
function rows()
{
$("#ingredients tr").each(function() {
var ingr= $(this).find("td").eq(2).html();
var prep= $(this).find("td").eq(3).html();
var quant= $(this).find("td").eq(4).html();
alert(prep);
});
alert("something");
}
Here is my table:
<TABLE name="ingredients" id="dataTable" width="350px" align="center" border="0">
<TR>
<td></td>
<td>Ingredient</td>
<td>Preparation</td>
<td>Amount</td>
</tr>
<tr>
<td><input type="checkbox" name="chk"/></td>
<TD>
<SELECT name="ingredient">
<?php
$db = new mysqli('localhost','root','mellon','recipes');
if($db->connect_errno >0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$query="select * from ingredients;";
if(!$results= $db->query($query)){
die('There was an error running the query [' . $db->error . ']');
}
while($row = $results->fetch_assoc()){
echo "<option value=\'" . $row['name'] . ">" . $row['name'] . " (" . $row['units'] . ")" . "</option>";
}
$results->free();
$db->close();
?>
</SELECT>
</TD>
<TD><INPUT type="text" name="prep"/></TD>
<TD><INPUT type="text" name="quantity"/></TD>
</TR>
</TABLE>