Forum Moderators: coopster

Message Too Old, No Replies

function to write option list

option list not work

         

threebytes

12:59 am on Dec 15, 2003 (gmt 0)

10+ Year Member



i have problem with the following function by where i was not able to get the $id display from database. and i have no problem with $data. is there anything got to do with primary key? shouldn't be right? then it would be sytax error? but i checked for so many times but still can't figure out what's wrong with it.

id tinyint(2) - primary key
data char(100 )

function writeOptionList( $table,$field )
{
global $connect;

$result = mysql_query( "SELECT $field FROM $table", $connect );
if (! $result )
{
print "failed to open $table<p>";
return false;
}

while ( $a_row = mysql_fetch_array( $result ) ){
print "<option value=\"$a_row[id]\"";

print ">$a_row[data]\n"; } }

threebytes

1:05 am on Dec 15, 2003 (gmt 0)

10+ Year Member



oh almost forget here is how the output look like
<select name="the_name
<option value="">data 1
<option value="">data 2
<option value="">data 3
<option value="">data 4
</select>

it have a blank value for it. by where if i switch the both value. the other side will have a blank value. i am sure the field exist in the database but what could be wrong.

coopster

1:59 pm on Dec 15, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Looks to me like your
id
column contains a NULL value. Have you populated it yet? Side note --> the syntax on your <select> tag is not correct.

threebytes

12:42 pm on Dec 16, 2003 (gmt 0)

10+ Year Member



haha, i just got the problem solve. did you guys figure it out? the problem was i only select one of the field. these why this thing doesn't work. so i just have to change to *

haha silly me.

coopster

4:07 pm on Dec 16, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



LOL, I missed it too. I'm surprised you didn't get an error message for trying to use an undefined index.