|
|
|
อยากทราบโค้ด php ของ ช่องSelect menu ที่ดึงรายชื่อมาจากฐานข้อมูลครับ |
|
|
|
|
|
|
|
Code (PHP)
<?php
$con = mysql_connect("localhost","root","root");
mysql_select_db("ebook",$con);
mysql_query("SET NAMES UTF8");
$sql = "select * from author;";
$rs = mysql_query($sql,$con);
?>
<select name="cols">
<?php
while($cols = mysql_fetch_row($rs)){
?>
<option value="<?=$cols[id]?>"><?=$cols["name"]?></option>
<?php
}
?>
</select>
|
ประวัติการแก้ไข 2017-09-09 13:58:25
|
|
|
|
Date :
2017-09-09 13:57:37 |
By :
kaidohjung |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เอาไปประยุกต์เอานะครับ
Code (PHP)
<?php
$db=new mysqli('localhost','test','test', 'test');
if($db->connect_errno) die($db->connect_error);
if(!($rs=$db->query("select id, name from (
select 1 as id, 'ทดสอบ1' as name
union select 2, 'ทดสอบ2'
union select 3, 'ทดสอบ3'
union select 4, 'ทดสอบ4'
) as tb"))) die($db->error);
?><!DOCTYPE html>
<html lang="en">
<head>
<!-- Basic Page Needs
================================================== -->
<meta charset="utf-8">
<!--[if IE]><meta http-equiv="x-ua-compatible" content="IE=9" /><![endif]-->
<title>Test Select</title>
<script src="asset/js/jquery-1.11.2.min.js"></script>
<script>
$(document).ready(function(e) {
$('#slc').change(function(e) {
$('#nme').val($(this).find('option:selected').text());
});
});
</script>
</head>
<body>
<b>name</b>
<select id="slc">
<option value="" selected disabled>-- กรุณาเลือก --</option>
<?php while($ro=$rs->fetch_object()):?>
<option value="<?=$ro->id?>"><?=$ro->name?></option>
<?php endwhile;?>
</select>
<br>
<b>show</b>
<input type=text id="nme">
</body>
</html>
|
|
|
|
|
Date :
2017-09-09 19:21:45 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|