php mysql ขอความช่วยเหลือหน่อยครับ ต้องการดึงข้อมูลจาก mysql
ทำไมคุณรันไฟล์แบบนั้นครับ น่าจะเป็น http://localhost/project/food.php ครับ
Date :
2012-11-15 16:25:58
By :
mr.win
ผมแค่เซฟหน้าจอมาให้ดูเฉยๆครับ ลองเปิดไฟล์จากในเครื่องอะครับ
Date :
2012-11-15 16:38:39
By :
porzza99
Code (PHP)
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<style>
body{font-family:Arial;font-size:12px;}
label{ text-align:right;font-weight:bold;width:100px;display:inline-block;}
input[type=text]{width:200px;border:solid 1px #CCC;background-color:#FF0;}
</style>
<title>Ajax JSON</title>
<meta charset="UTF-8" />
</head>
<body>
<h2>Application Information</h2>
<form name='Myfrm'>
<label style='color:#F00;'>Select : </label>
<select name='DDl' id='DDl'>
<option value="0">--SELECT--</option>
<?php
$link = mysql_connect('localhost', 'root', '1234') or die (mysql_error());
$sel_db = mysql_select_db('student_db', $link);
$sql = "SELECT Id_std, Name FROM tb_student";
$qr = mysql_query($sql);
while($rsObj = mysql_fetch_array($qr)){
echo "<option value=\"".$rsObj['Id_std']."\">".$rsObj['Name']."</option>";
}
?>
</select><br /><br />
<label>ID : </label>
<input type='text' name='txt_id' id='txt_id'><br /><br />
<label>Name : </label>
<input type='text' name='txt_name' id='txt_name'><br /><br />
</form>
<script type='text/javascript'>
$(document).ready(function(){
$('#DDl').change(function(){
var id = $('#DDl').val();
if(id == 0){
$('#txt_id').val('');
$('#txt_name').val('');
}else{
$.getJSON('Get_val.php?tMode=getdata&id='+id, function(data){
$('#txt_id').val(data[0].Id_std);
$('#txt_name').val(data[0].Name);
});
//return false;
}
});
});
</script>
</body>
</html>
Code (PHP)
<?php
/* Fix request sometime don't dupicate */
header("Content-type:text/html; charset=UTF-8");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
$link = mysql_connect("localhost", "root", "1234") or die (mysql_error());
$sel_db = mysql_select_db("student_db", $link);
if($_GET['tMode'] == 'getdata'){
$sql = "SELECT Id_std, Name FROM tb_student WHERE Id_std = '".$_GET['id']."' ";
$qr = mysql_query($sql) or die(mysql_error());
$fetch = mysql_fetch_assoc($qr);
$json_arr[] = array('Id_std'=>$fetch['Id_std'], 'Name'=>$fetch['Name'],);
$json_data = json_encode($json_arr);
echo $json_data;
}
?>
Date :
2012-11-16 09:16:32
By :
popnakub
Load balance : Server 00