I could use some help understanding what my code is doing or trying to do. I have an html form where you select an isbn from a drop down menu. Once you select an isbn and click update the action is to go to update.php. Before this happens, my php code selects the isbn field in the book table and counts the number of rows? Does this sound correct?
The loop portion of my code, which is this:
Is this what counts the number of rows in the book table? This value is what gets stored in the $num_rows variable? I'm confused because I thought the array variable i is the variable which holds the total number of rows after the loop is completed?PHP Code:for($i=0; $i<=$num_rows; $i++){
$select = mysql_fetch_array("$result_2")
echo "<option>" . $select[ ISBN ];
}
PHP Code:<html>
<head>
<title>Update Price</title>
</head>
<body>
<h1>Update Price</h1>
<form name="test" action="update.php" method="post">
<table border="0">
<tr>
<td>ISBN
<select name="ISBN">
<option> 0-672-31697-8 </option>
<option> 0-672-31769-9 </option>
<option> 0-672-31509-2 </option>
<option> 0-672-31745-1 </option>
</td>
<tr>
<?PHP
include("connect.php");
$query_2 = "Select ISBN from books;"; #query
$result_2 = mysql_query($query_2) or die ("Query 2 Failed!"); #run the query
$num_rows = mysql_num_rows($result_2); #returns an "int" number of rows
for($i=0; $i<=$num_rows; $i++){
$select = mysql_fetch_array("$result_2")
echo "<option>" . $select[ ISBN ];
}
?>
</select>
<td>Price $</td>
<td><input type="text" name="price" maxlength="7" size="7"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="update" value="Update">
</td>
</tr>
</table>
</form>
</body>
</html>




Reply With Quote