|
|
|
php อยากทราบว่า dropdownlist สามารถกำหนดค่า default ให้เลือกไว้ได้ไหมค่ะ |
|
|
|
|
|
|
|
Code (PHP)
<?php
$host = "localhost";
$database = "db";
$username = "root";
$password = "1234";
$connect = mysql_connect($host, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database, $connect_mk);
$sql = "SELECT name,surname,sex_id, FROM person LIMIT 1";
$result = mysql_query( $sql, $connect);
$fd = mysql_fetch_array($result);
?>
<select name="select_sex">
<option value="">- เลือกเพศ -</option>
<?php
mysql_select_db($database, $connect_mk);
$sql = "SELECT sex_id,sex_name FROM sex";
$result = mysql_query( $sql, $connect);
while ($rs = mysql_fetch_array($result))
{
if ($rs['sex_id'] == $fd['sex_id'])
echo "<option value=\"$rs[sex_id]\" selected>$rs[sex_name]</option>\n";
else
echo "<option value=\"$rs[sex_id]\">$rs[sex_name]</option>\n";
}
?>
</select>
|
ประวัติการแก้ไข 2011-03-07 16:38:50
|
|
|
|
Date :
2011-03-07 16:38:15 |
By :
avsqlz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<select name="lmName1">
<option value=""><-- Please Select Item --></option>
<?
$strSQL = "SELECT * FROM customer ORDER BY CustomerID ASC";
$objQuery = mysql_query($strSQL);
while($objResuut = mysql_fetch_array($objQuery))
{
if($strDefault == $objResuut["CustomerID"])
{
$sel = "selected";
}
else
{
$sel = "";
}
?>
<option value="<?=$objResuut["CustomerID"];?>" <?=$sel;?>><?=$objResuut["CustomerID"]." - ".$objResuut["Name"];?></option>
<?
}
?>
</select>
Go to : PHP MySQL DropDownList / Listmenu / ListBox
|
|
|
|
|
Date :
2011-03-07 16:44:32 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|