Forum Moderators: coopster
my "if else" does not echo the previously selcted value that is correctly entered in the DB
I can change category and get correct new value in the DB
but cannot echo the selected value
thanks
<<<
Choose a Category:<br>
<select name="category" Wrap=virtual>
<option value="ag">
<?
$query= "select category from templates where username= '$username' and page= '$page' ";
$result=mysql_query($query);
while($query_data=mysql_fetch_array($result) ){
$category=($query_data["category"]);
}
if ($category=="ag") echo "Selected: AGRICULTURE ";
else echo "AGRICULTURE";
?> </option>
>>>
Choose a Category:<br>
<select name="category" Wrap=virtual>
<?
$query= "select category from templates where username= '$username' and page= '$page' ";
$result=mysql_query($query);
while($query_data=mysql_fetch_array($result) ){
$category=($query_data["category"]);
}
if ($category=="ag") {
echo "<option value=\"ag\" selected>Selected: AGRICULTURE</option>";
} else {
echo "<option value=\"ag\">AGRICULTURE</option>";
}
?>
still no effects from the "if..Else.."
as mentioned I can change the values
but it is still not showing the selected category
and still defaulting back to "agriculture"
so if an Attorney edits its content
and do not select again "law" its category will become "agriculture" :)
<edit>
I am not sure that in the option double quotes need to be escaped?
</edit>
<edit_2>
My mistake - need to be escaped - </edit>
$num = mysql_num_rows($result);
Put this in and then echo the var $num. If it returns 0 then you're not getting any results back. This means something is wrong with the query or there is no data in the table that matches.
Also, what is following after the php bit of code?
while($query_data=mysql_fetch_array($result) ){
$category=($query_data["category"]);
}
If you only have one record in the db that matches the query then the while would be OK. But if you had more than one you will keep changing the value to the last record returned.
That's why it's important to know what the last matching record value is. As wonderbread pointed out....it may also be null which would fail. So if you have two records in the db and the natural order has the category of 'ag' but the next one has a value of 'bh' or null it will fail.
JAG
JAG
to verify your last post I (on my test server) deleted all records to have only one vaue left
and it does not change anything
I am afraid that I have to rethink that all select box solution
Henry
I have a solution which consists in separating the category choice from the editable content
which can be done but it will not be elegant
and I will not learn anything!