Forum Moderators: coopster

Message Too Old, No Replies

Displaying the value selected by user

         

Shaman13

5:01 pm on Dec 29, 2004 (gmt 0)

10+ Year Member



Greetings! I am baffled by this and I shouldn't be. My problem is how do I get the select box below to display the users choice (which they made when they initially completed the form) when they subsequently open the form to view their entries. Any and all suggestions are appreciated. Without the folks in this forum I would be banging my head against the wall! Thanks
---------------------------------------------------
<select name='CASEACTIVITY'>
<?php

$result = mysql_fetch_array(mysql_query("SELECT CASEACTIVITY FROM ttime WHERE TIMEID = '$TIMEID'"));
$user_val = $result['CASEACTIVITY'];

$query = mysql_query("SELECT * FROM subcaseactivity");
while($array = mysql_fetch_array($query)) {
if($array['id'] == $user_val) {
print "<option selected value=$array[id]>$array[name]</option>";
} else {
print "<option value=$array[id]>$array[name]</option>";
}
}
?>
</select>

CaseyRyan

5:09 pm on Dec 29, 2004 (gmt 0)

10+ Year Member



if($array['id'] == $user_val)

Are you sure that the above comparison is correct? Are you comparing the ID values or the name values?

Without knowing much about your database: IN the rest of your code you reference $array[id] instead of id in the single quotes. Maybe that is a problem.

One way to debug this would be to output the value you are retreiving form the database ($user_val). Try printing that out to the page to see if it is even returning a value.

-=casey=-

Shaman13

6:01 pm on Dec 29, 2004 (gmt 0)

10+ Year Member



Casey Thanks for the suggestions! I am trying to match on id. And when I tried to print $user_val to the page it doesn't seem to work. Other suggestions I should try. Thanks again for the help!

CaseyRyan

6:39 pm on Dec 29, 2004 (gmt 0)

10+ Year Member



If you're not able to get the $user_val to print out then I would say there is something wrong with this statement:
$result = mysql_fetch_array(mysql_query("SELECT CASEACTIVITY FROM ttime WHERE TIMEID = '$TIMEID'"));

I would guess that it isn't returning any information.
Where do you get $TIMEID from? Try printing out the $TIMEID value like you did for $user_val.

Also, in your sql statement you wrap the $TIMEID in quotes. If this is an integer column then you should not do that.

-=casey=-

Shaman13

8:39 pm on Dec 29, 2004 (gmt 0)

10+ Year Member



Casey

Thanks so much for lending another pair of eyes to my code. You were right my query was not pulling information. I double checked it and presto! It works just fine. Thanks for the suggestions and the help. Have an Awesome Day!