//Start of form echo "<form action=\"cat.php\" method=\"post\">\n"; $query="SELECT category_id, category_name FROM category "; // start to read database values $result = mysql_query ($query); echo "<select name=category_id value=''><option> Select your category </option>";// printing the list box select command while($nt=mysql_fetch_array($result))/* Option values are added by looping through the array */ { echo "<option value=$nt[category_id]> $nt[category_name]</option>";//Array or records stored in $nt } echo "</select>";// Closing of list box */ echo "<br/>"; $category_id=$nt['category_id']; $category_id=$_GET['category_id']; $category_id=2;// here I default the value and the db produces the correct result //$query="SELECT DISTINCT manufacturer_name, category_id //FROM manufacturer //"; $query="SELECT DISTINCT manufacturer.manufacturer_name FROM category as category JOIN vehicles as vehicles on category.category_ID = vehicles.FK_category_ID JOIN products as products on products.products_id = vehicles.FK_products_ID JOIN manufacturer as manufacturer on manufacturer.manufacturer_ID = vehicles.FK_manufacturer_ID WHERE vehicles.FK_category_ID = '$category_id' "; // start to read database values $result = mysql_query ($query); echo "<select name=manufacturer_name value=''><option> Select your category </option>"; // printing the list box select command while($nt=mysql_fetch_array($result)) { //Array or records stored in $nt echo "<option value=$nt[manufacturer_id]> $nt[manufacturer_name]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box */ //Should this be capturing data from the highlighted red code? echo"<input type=\"hidden\" name=\"make\" value=\"$make\">";// this value is know in the page // echo"<input type=\"hidden\" name=\"category_id\" value=\"$category_id\">";// this value is know in the page echo "<br/>"; echo "<br/>"; echo" <input type=\"submit\" value=\"Search\">\n"; echo"</form>";
[code=php] tags so we can read it clearly and respond quoting line numbers.<select name=category_id value=''> on line 9 you are trying to access a value from the database, but you haven't read a row yet, that doesn't happen till line 11, so the value is not yet accessible. You've read all the rows into an array on line 8, but you haven't actually started the loop that reads each row, that starts on line 11. That's what you need to do to access the values.<select> control doesn't normally come from a database unless you are trying to loop through the categories creating a select list from each, which is a whole different ball game. Doable, but different.
//Start of form echo "<form action=\"cat.php\" method=\"post\">\n"; $query="SELECT category_id, category_name FROM category "; // start to read database values $result = mysql_query ($query); echo "<select name=category_id value=''><option> Select your category </option>";// printing the list box select command while($nt=mysql_fetch_array($result))/* Option values are added by looping through the array */ { echo "<option value=$nt[category_id]> $nt[category_name]</option>";//Array or records stored in $nt } echo "</select>";// Closing of list box */ echo "<br/>"; $category_id=$nt['category_id']; $category_id=$_GET['category_id']; $category_id=2;// here I default the value and the db produces the correct result //$query="SELECT DISTINCT manufacturer_name, category_id //FROM manufacturer //"; $query="SELECT DISTINCT manufacturer.manufacturer_name FROM category as category JOIN vehicles as vehicles on category.category_ID = vehicles.FK_category_ID JOIN products as products on products.products_id = vehicles.FK_products_ID JOIN manufacturer as manufacturer on manufacturer.manufacturer_ID = vehicles.FK_manufacturer_ID WHERE vehicles.FK_category_ID = '$category_id' "; // start to read database values $result = mysql_query ($query); echo "<select name=manufacturer_name value=''><option> Select your category </option>"; // printing the list box select command while($nt=mysql_fetch_array($result)) { //Array or records stored in $nt echo "<option value=$nt[manufacturer_id]> $nt[manufacturer_name]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box */ //Should this be capturing data from the highlighted red code? echo"<input type=\"hidden\" name=\"make\" value=\"$make\">";// this value is know in the page // echo"<input type=\"hidden\" name=\"category_id\" value=\"$category_id\">";// this value is know in the page echo "<br/>"; echo "<br/>"; echo" <input type=\"submit\" value=\"Search\">\n"; echo"</form>";
// ---------- BUILD FIRST SELECT LIST: CATEGORIES ---------- // // get categories from db $query="SELECT category_id, category_name FROM category "; $result = mysql_query ($query); // open the form echo "<form action=\"cat.php\" method=\"post\">\n"; // build the select list echo "<select name=category_id value=''><option> Select your category </option>";// printing the list box select command while($nt=mysql_fetch_array($result))/* Option values are added by looping through the array */ { echo "<option value=$nt[category_id]> $nt[category_name]</option>";//Array or records stored in $nt } echo "</select>"; echo "<br/>"; // ---------- BUILD SECOND SELECT LIST: MANUFACTURERS ---------- // // initialize some values $category_id = $nt['category_id']; $category_id = $_GET['category_id']; $category_id = 2; // here I default the value and the db produces the correct result // set up the SQL query $query="SELECT DISTINCT manufacturer.manufacturer_name FROM category as category JOIN vehicles as vehicles on category.category_ID = vehicles.FK_category_ID JOIN products as products on products.products_id = vehicles.FK_products_ID JOIN manufacturer as manufacturer on manufacturer.manufacturer_ID = vehicles.FK_manufacturer_ID WHERE vehicles.FK_category_ID = '$category_id' "; // query the database $result = mysql_query ($query); // set up the next select list. echo "<select name=manufacturer_name value=''><option> Select your category </option>"; // printing the list box select command while($nt=mysql_fetch_array($result)) { //Array or records stored in $nt echo "<option value=$nt[manufacturer_id]> $nt[manufacturer_name]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box */ //Should this be capturing data from the highlighted red code? echo"<input type=\"hidden\" name=\"make\" value=\"$make\">";// this value is know in the page // echo"<input type=\"hidden\" name=\"category_id\" value=\"$category_id\">";// this value is know in the page echo "<br/>"; echo "<br/>"; echo" <input type=\"submit\" value=\"Search\">\n"; echo"</form>";
echo "Test for category_id: ".$nt['category_id']." - ".$category_id = $_GET['category_id']; around line 19 of my version.| DaniWeb Message | |
| Cancel Changes | |