เกี่ยวกับ ปัญหาการใช้งาน การติดตั้ง ฐานข้อมูล MySql Oracle MSSQL ect...
การเขียน คำสั่ง SQL เพื่อดึกข้อมูล บอร์ดนี้ควรระบุโครงสร้างตารางของท่านในคำถามด้วยนะ
Moderator: mindphp
-
bigbird
- PHP Newbie
- โพสต์: 3
- ลงทะเบียนเมื่อ: 09/04/2013 3:00 pm
โพสต์ที่ยังไม่ได้อ่าน
โดย bigbird »
รบกวนท่านผู้รู้ทั้งหลายหน่อยครับ
ผมต้องการ query ข้อมุล มาใส่ใน list menu แล้ว ส่งค่าไปยัง DB เป็น ตัวเลขครับ ต้องทำยังไครับ
ตัวอย่าง เช่น
ตาราง hospital_building_ds มีฟิลด์ดังนี้ ครับ
+---+-----------+
| id | name |
| 1 |ห้องตรวจ 1 |
| 2 |ห้องตรวจ 2 |
| 3 |ห้องตรวจ 3 |
| 4 |ห้องตรวจ 4 |
| 5 |ห้องตรวจ 5 |
+---+-----------+
ดึงข้อมูลออกมาแบบนี้ครับ
โค้ด: เลือกทั้งหมด
<select name="point" id="point" >
<option value="">- กรุณาเลือก -</option>
<? $sql1="select name from hospital_building_ds order by id" ;
$result1 = mysql_query($sql1);
while($dbarr1=mysql_fetch_array($result1)){
echo"<option value='".$dbarr1['id'] . "'>" .$dbarr1['name']. "</option>";
}
?>
</select>
<input name="point" type="hidden" id="point" value="point" />
ต้องการเอาฟิลด์ id ไปเก็บในฐานข้อมูล ต้องทำยังไงครับ มึนมา 2 วันละครับ
ขอบคุณครับ
แก้ไขล่าสุดโดย
bigbird เมื่อ 12/04/2013 10:49 am, แก้ไขไปแล้ว 1 ครั้ง.
กัมปนาท บุตรจันทร์ (เบิร์ด) จพง.คอมพิวเตอร์ รพ.จิตเวชเลยราชนครินทร์
-
mindphp
- ผู้ดูแลระบบ MindPHP
- โพสต์: 41231
- ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
-
ติดต่อ:
โพสต์ที่ยังไม่ได้อ่าน
โดย mindphp »
ตอน query ยังไม่ได้ ระบุว่าเอา id มาด้วยครับ
โค้ด: เลือกทั้งหมด
select name from hospital_building_ds order by id
หลัง name เพิ่ม , ชื่อ filed ที่ต้องการเอามาใช้
-
bigbird
- PHP Newbie
- โพสต์: 3
- ลงทะเบียนเมื่อ: 09/04/2013 3:00 pm
โพสต์ที่ยังไม่ได้อ่าน
โดย bigbird »
โค้ด: เลือกทั้งหมด
<select name="point" id="point" >
<option value="">- กรุณาเลือก -</option>
<? $sql1="select name,id from hospital_building_ds order by id" ;
$result1 = mysql_query($sql1);
while($dbarr1=mysql_fetch_array($result1)){
echo"<option value='".$dbarr1['id'] . "'>" .$dbarr1['name']. "</option>";
}
?>
</select>
<input name="point" type="hidden" id="point" value="point" />
เพิ่มแล้วครับ แล้วทีนี้ผม echo ถูกหรือยังครับ ไฟล์ insert.php ผมประมาณนี้ครับ
โค้ด: เลือกทั้งหมด
<?php
session_start() ;
$_SESSION['post']=$_POST;
$_SESSION['error']="";
$hn=$_GET['hn'];//ตั้งค่าตัวแปล
$point=$_POST['point'];
$hosdep=$_POST['id'];
$hosdep2=$_POST['id'];
$rsubject=$_POST['subject_id'];
$typeriskall=$_POST['type_id'];
$typeriskallsub=$_POST['type_sub_id'];
$risklevel=$_POST['level_name'];
$rrp=$_POST['name'];
$typereason=$_POST['reason_id'];
$typereasonsystem=$_POST['id'];
require_once("connect.php");
if (trim ($point==""))//ตรวจสอบฟิลด์ที่ไม่ได้กรอกกรอกข้อมูล
{
$_SESSION['error']['point']='กรุณาระบุจุดเกิดอุบัติการณ์';
} if(trim ($hosdep=="")){
$_SESSION['error']['id']='กรุณาเลือกหน่วยงานที่เกี่ยวข้อง';
} if(trim ($hosdep2=="")){
$_SESSION['error']['id']='กรุณาเลือกหน่วยงานที่รายงาน';
} if(trim ($rsubject=="")){
$_SESSION['error']['subject_id']='กรุณาเลือกลักษณะอุบัติการณ์';
} if(trim ($typeriskall=="")){
$_SESSION['error']['type_id']='กรุณาเลือกรายละเอียด';
} if(trim ($typeriskallsub=="")){
$_SESSION['error']['type_sub_id']='กรุณาเลือกรายละเอียดย่อย';
} if(trim ($risklevel=="")){
$_SESSION['error']['level_name']='กรุณาเลือกระดับความรุนแรงของอุบัติการณ์';
} if(trim ($rrp=="")){
$_SESSION['error']['name']='กรุณาเลือกประเภทใบอุบัติการณ์';
echo "<script> window.history.go(-1);</script>\n";
exit();
}else{
$sql="INSERT INTO risk_report_ds (hn,department_link,department_relevant,reason,reason_system,type_risk_all,type_risk_all_sub)VALUES ('$hn','$point','$hosdep',$hosdep2','$typereason','$typereasonsystem','$typeriskall','$typeriskallsub')";//คำสั่งเพิ่มข้อมูล
$sql_query=mysql_query($sql);
if($sql_query) {
echo "<script type='text/javascript'>alert('บันทึกข้อมูลเรียบร้อยแล้ว')</script>";
echo "<meta http-equiv ='refresh'content='0;URL=show.php'>";
$_SESSION['post']="";
}else{
echo "<script type='text/javascript'>alert('เกิดข้อผิดพลาดในการบันทึกข้อมูล');window.history.go(-1);</script>" ;
}
}
mysql_close();
?>
กัมปนาท บุตรจันทร์ (เบิร์ด) จพง.คอมพิวเตอร์ รพ.จิตเวชเลยราชนครินทร์
-
bigbird
- PHP Newbie
- โพสต์: 3
- ลงทะเบียนเมื่อ: 09/04/2013 3:00 pm
โพสต์ที่ยังไม่ได้อ่าน
โดย bigbird »
ตอนนี้กดปุ่ม บันทึก แล้ว ไม่ไปไหนเลยครับ
โค้ด: เลือกทั้งหมด
<?php
session_start ();
if (isset($_SESSION['post'])){
$post=$_SESSION['post'];
}else{
$post=array();
}
if (isset($_SESSION['error'])){
$error=$_SESSION['error'];
}else{
$error=array();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../jquery-ui-1.7.2.custom/css/smoothness/jquery-ui-1.7.2.custom.css">
</head>
<body>
<ul data-role="listview" data-theme="d" data-inset="true" data-split-theme="a" data-divider-theme="b">
<li data-role="list-divider" >
<div align="center">
<strong>บันทึกอุบัติการณ์</strong>
<form id="addrisk1" name="addrisk1" method="post" action="insert_risk.php">
<table width="100%">
<tr>
<td>HN (ถ้ามี)</td>
<td><input name="hn" type="text" maxlength="7" id="hn"/></td>
</tr>
</table>
<table width="100%">
<tr>
<td width="20%">สถานที่เกิดเหตุ</td>
<td width="30%"><select name="point" id="point" >
<option value="">- กรุณาเลือก -</option>
<? $sql1="select * from hospital_building_ds order by id" ;
$result1 = mysql_query($sql1);
while($dbarr1=mysql_fetch_array($result1)){
echo"<option value='".$dbarr1['id'] . "'>" .$dbarr1['name']. "</option>";
}
?>
</select>
<input name="point" type="hidden" id="point" value="point" />
</td>
<td width="20%" align="right">วันที่เกิดเหตุ</td>
<td width="30%"><input type="text" name="dc12">
<a href="javascript:void(0)" onClick="if(self.gfPop)gfPop.fPopCalendar(document.form1.dc12);return false;" ><img class="PopcalTrigger" align="absmiddle" src="PopCalendarXP/calbtn.gif" width="34" height="22" border="0" alt=""></a></td>
<td height="31" colspan="4"><a href="javascript:void(0)" onClick="if(self.gfPop)gfPop.fPopCalendar(document.form1.dc12);return false;" ></a> <div align="left"></div></td>
</tr>
<tr>
<td width="20%">หน่วยงานที่เกี่ยวข้อง:</td>
<td width="30%"><select name="hosdep1" id="hosdep1">
<option value="">- กรุณาเลือก -</option>
<? $sql2="select name from hospital_department order by id" ;
$result2 = mysql_query($sql2);
while($dbarr2=mysql_fetch_array($result2)){
echo"<option value='".$dbarr2['id'] . "'>" .$dbarr2['name']. "</option>";
}
?>
</select>
<input type="hidden" name="action" id="action" value="true"/>
</td>
<td width="20%" align="right">วันที่รายงาน</td>
<td width="30%"><input type="text" name="dateInput" id="dateInput" /></td>
</tr>
<tr>
<td width="20%">หน่วยงานที่รายงาน</td>
<td width="30%"><select name="hosdep2" id="hosdep2" >
<option value="">- กรุณาเลือก -</option>
<? $sql3="select name from hospital_department order by id" ;
$result3 = mysql_query($sql3);
while($dbarr3=mysql_fetch_array($result3)){
echo"<option value='".$dbarr3['id'] . "'>" .$dbarr3['name']. "</option>";
}
?>
</select>
<input type="hidden" name="action" id="action" value="true"/>
</td>
<td><div align="right">ระดับความรุนแรง</div></td>
<td><select name="risklevel" id="risklevel">
<option value="">- กรุณาเลือก -</option>
<? $sql5="select * from risk_level" ;
$result5 = mysql_query($sql5);
while($dbarr5=mysql_fetch_array($result5)){
echo"<option value='".$dbarr5['id'] . "'>" .$dbarr5['level_name']. "</option>";
}
?>
</select>
<input type="hidden" name="action2" id="action2" value="true" /></td>
</tr>
<tr>
<td>ลักษณะอุบัติการณ์</td>
<td><select name="rsubject" id="rsubject">
<option value="" selected="selected">- กรุณาเลือก -</option>
<? $sql4="select * from risk_subject order by subject_id" ;
$result4 = mysql_query($sql4);
while($dbarr4=mysql_fetch_array($result4)){
echo"<option value='".$dbarr4['subject_id'] . "'>" .$dbarr4['name']. "</option>";
}
?>
</select>
<input type="hidden" name="action" id="action" value="true" />
</td>
<td align="right">ประเภทใบอุบัติการณ์</td>
<td><select name="ir" id="ir">
<option value="">- กรุณาเลือก -</option>
<? $sql7="select name from risk_relation_program" ;
$result7=mysql_query($sql7);
while($dbarr7=mysql_fetch_array($result7)){
echo"<option value='".$dbarr7['id'] . "'>" .$dbarr7['name']. "</option>";
}
?>
</select>
<input type="hidden" name="action3" id="action3" value="true"/></td>
</tr>
<tr>
<td>รายละเอียด</td>
<td><select name="typeriskall" id="typeriskall">
<option value="">- กรุณาเลือก -</option>
<?
$sql6="select * from type_risk_all";
$result6=mysql_query($sql6);
while($dbarrp2=mysql_fetch_array($result6)){
echo"<option value='".$dbarr6['id'] . "'>" .$dbarr6['name']. "</option>";
}
?>
</select>
<input type="hidden" name="action" id="action" value="true"/>
</td>
<td align="right">สาเหตุที่ชัดแจ้ง</td>
<td><select name="typereason" id="typereason" >
<option value="">- กรุณาเลือก -</option>
<? $sql9="select name from type_reason order by reason_id" ;
$result9 = mysql_query($sql9);
while($dbarr9=mysql_fetch_array($result9)){
echo"<option value='".$dbarr9['id'] . "'>" .$dbarr9['name']. "</option>";
}
?>
</select>
<input type="hidden" name="action4" id="action4" value="true"/></td>
</tr>
<tr>
<td>รายละเอียดย่อย</td>
<td><select name="typeriskallsub" id="typeriskallsub">
<option value="">- กรุณาเลือก -</option>
<? $sql8="select * from type_risk_all_sub where subject_id='1' and type_id='1'" ;
$result8 = mysql_query($sql8);
while($dbarr8=mysql_fetch_array($result8)){
echo"<option value='".$dbarr8['id'] . "'>" .$dbarr8['name']. "</option>";
}
?>
</select>
<input type="hidden" name="action" id="action" value="true"/>
</td>
<td align="right">สาเหตุเชิงระบบ</td>
<td><select name="system" id="system" >
<option value="">- กรุณาเลือก -</option>
<? $sql10="select name from type_reason_system order by id" ;
$result10 = mysql_query($sql10);
while($dbarr10=mysql_fetch_array($result10)){
echo"<option value='".$dbarr10['id'] . "'>" .$dbarr10['name']. "</option>";
}
?>
</select>
<input type="hidden" name="action5" id="action5" value="true"/></td>
</tr>
<td colspan="4">
<textarea name="text_risk" cols="100" rows="10"></textarea>
</td>
</table>
<button type="submit" data-theme="b" data-inline="true" data-mini="true" data-icon="check" name="button" id="button" value="ตกลง">บันทึก</button>
<button type="reset" data-theme="b" data-inline="true" data-mini="true" data-icon="check" name="button2" id="button2" value="ยกเลิก">ล้างข้อมูล</button>
</h4>
</form>
</li>
</ul>
</body>
<iframe width=174 height=189 name="gToday:normal:agenda.js" id="gToday:normal:agenda.js" src="PopCalendarXP/ipopeng.htm" scrolling="no" frameborder="0" style="visibility:visible; z-index:999; position:absolute; top:-500px; left:-500px;">
</iframe>
</html>
กัมปนาท บุตรจันทร์ (เบิร์ด) จพง.คอมพิวเตอร์ รพ.จิตเวชเลยราชนครินทร์
-
-
- 0 ตอบกลับ
- 1256 แสดง
-
โพสต์ล่าสุด โดย jayyyyyyyyyy
27/08/2014 6:14 pm
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 68