RE: Re: Display Mysql Result in drop down list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I am looking at your code and have a question, in your code you have

print "<OPTION VALUE=\"$tutor_name\" SELECTED>" .$row ["tutor_name"].
"</option>"; 

Doesn't the SELECTED piece mark everything listed as selected?? When you
bring up the page with the drop down list and open the source, what does it
show??

I handle this  a little differently, I create my drop down list as follows:

=================== Code used ============================================

// First I retrieve all customer information

$BB = mysql_query("SELECT * FROM customer ORDER BY CID ");



// Then I create the drop down list

<SELECT style="WIDTH: 410px" size=1 name="Customer">


<?
 // Creates the Customer dropdown with the $id number
   while ($Site = mysql_fetch_array($BB)) 
  {
    $Sid = $Site["CID"];
    $Sname = htmlspecialchars($Site["Customer"]);
    $SCity = htmlspecialchars($Site["City"]);
    $SState = htmlspecialchars($Site["State"]);
    $SCountry = htmlspecialchars($Site["Country"]);


	if($Sid == $Customer) 
	{ $add = ' selected'; } else { $add = ''; } 
 
    echo("<option value='$Sid'$add>$Sname &nbsp;&nbsp;&nbsp; $SCity
&nbsp;&nbsp;&nbsp; $SState &nbsp;&nbsp;&nbsp; $SCountry </option>\n");  

  }
 
?>

</select>

=================== Code used ============================================

This will create a drop down list where the value of the option is the sites
ID. In another part of this form, if there is a value set for $Customer,
then it will set the $add to selected. This will then make the drop down
list auto select the customer.

The code above is passed to another form for processing and is were the
insert data occurs. Using this method I can echo the form data easily....

Hope this helps...

Aleks



-----Original Message-----
From: irinchiang@xxxxxxxxxxxxxxxxx [mailto:irinchiang@xxxxxxxxxxxxxxxxx] 
Sent: Tuesday, December 23, 2003 4:33 AM
To: David Robley
Cc: php-db@xxxxxxxxxxxxx
Subject: Re:  Re: Display Mysql Result in drop down list

Hi:

then now i'm trying to select a value from the drop down list, echo the
value i have selected and lastly INSERT the value into DB with the following
:
Below's a snippet of code:

<snip>
//retrieve all "tutor_name" from DB and display in drop down list

<SELECT class="textarea" name="tutor_name" /> <?


$sql = mysql_query("SELECT tutor_name FROM tutor "); while ($row =
mysql_fetch_array($sql)) {  print "<OPTION VALUE=\"$tutor_name\" SELECTED>"
.$row ["tutor_name"]. "</option>";  }  $result = $db->query($sql);

?>
</select>

</snip>

<snip>
***********************INSERT selected values into
DB************************** $tutor_name = $_POST["tutor_name"];

$sql = "INSERT INTO class (class_code, tutor_name, edu_level, timetable_day,
timetable_time)
        VALUES
('$class_code','$tutor_name','$edu_level','$timetable_day','$timetable_time'
)";

//execute query statement
$result = $db->query($sql);

</snip>


<snip>
*********************echo the value i have
selected***************************
<?
if($selected_tutor_name == $tutor_name)
echo $_POST["tutor_name"];
?>

</snip>


Problem: I was unable to echo the value i selected from drop down as well as
INSERT into DB...wonder where have i gone wrong???
Reali need some help here...all help are greatly appreciated =) Thanks in
advance.


Irin.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux