Again, not sure of this is a PHP question or a mySQL (SQL) question, but I'll give it a shot.
I have a database with 3 tables in it (i'm sure I could get some lessons on DB design as well!).
Two of the tables are simply reference tables for category_id and region_id. So in my main data table I reference an ID for both region and category from these two tables. This all works fine. I can print out the details of the data and include the text from these two reference tables using the ID.
The problem I now have is in editing a record in the data table. I have managed to get an edit page setup for the data and even have drop boxes for region and category, using the code below (the example is for the caegory):
The problem with the above code is that it simply lists the options from the category table, rather the value stored in the main data table.
What I want is a list as above displayed on my edit page, but the value of these two fields (region and category) to be the value stored in the data table.
So the category_id stored in the data table might be 3, which relates to 'business' in the category table and I want that as the selected value in the edit form rather than just the first value from the select statement.
Make sense??
I have a database with 3 tables in it (i'm sure I could get some lessons on DB design as well!).
Two of the tables are simply reference tables for category_id and region_id. So in my main data table I reference an ID for both region and category from these two tables. This all works fine. I can print out the details of the data and include the text from these two reference tables using the ID.
The problem I now have is in editing a record in the data table. I have managed to get an edit page setup for the data and even have drop boxes for region and category, using the code below (the example is for the caegory):
Code:
<?php
include ('/blah/blah/includes/mysql_connect.php');
$query="SELECT id,category FROM category ORDER BY category";
$result = mysql_query ($query);
echo "Category: <select name='category'>";
while($cat=mysql_fetch_array($result)){
echo "<option value=$cat[id]>$cat[category]</option>";
}
echo "</select>";
?>
The problem with the above code is that it simply lists the options from the category table, rather the value stored in the main data table.
What I want is a list as above displayed on my edit page, but the value of these two fields (region and category) to be the value stored in the data table.
So the category_id stored in the data table might be 3, which relates to 'business' in the category table and I want that as the selected value in the edit form rather than just the first value from the select statement.
Make sense??