|
|
|
ช่วยแนะนำ select ข้อมูลphp จาก mysql แบบ sqli หน่อยครับ |
|
|
|
|
|
|
|
Code (PHP)
$query = "SELECT * FROM tb_wat INNER JOIN tb_monk ON tb_wat.id_wat = tb_monk.monk_id
INNER JOIN tb_novice ON tb_wat.id_wat = tb_novice.novice_id";
|
|
|
|
|
Date :
2017-05-05 21:25:22 |
By :
sak929 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แยกตาราง ระหว่างพระกับเณร แล้วทำเป็น query 3 ครั้งก็ได้ครับ (ถ้าหากข้อมูลไม่เยอะมาก)
Code (PHP)
<form action="" method="POST" name="f1">
<?php
/*** Connect ***/
$serverName = "localhost";
$userName = "root";
$userPassword = "123456";
$dbName = "sqltemple";
$objCon = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($objCon, "utf8");
//========== query1 ===========
$query1 = "SELECT * FROM tb_wat";
$result1 = mysqli_query($objCon,$query1)
?>
<center><br><br> <select name="s1">
<?
while($data1 = mysqli_fetch_array($result1))
{
$name_wat = $data1['name_wat'];
echo '<option value="'.$id_wat.'">'.$name_wat.'</option>';
}
?>
</select>
<input type="submit" name="button" id="button" value="OK" /> </center>
</form>
<br><br>
<?
//========== query2 ===========
$query2 = "SELECT * FROM tb_monk where id_wat = $_POST['id_wat']";
$result2 = mysqli_query($objCon,$query2);
?>
<center><h1>พระภิกษุ</h1></center>
<table id="table" width="800">
<tr>
<th>ชื่อ</th>
<th>ฉายา</th>
<th>สกุล</th>
</tr>
<?
while($data2 = mysqli_fetch_array($result2))
{
?>
<tr>
<td> <?php echo $data2["name_monk"]?> </td>
<td> <?php echo $data2["chaya_monk"]?> </td>
<td> <?php echo $data2["lastname_monk"]?> </td>
</tr>
<?
}
?>
</table>
<br /><br />
<?
//========== query3 ===========
$query3 = " SELECT * FROM tb_novice where id_wat = $_POST['id_wat']";
$result3 = mysqli_query($objCon,$query3);
?>
<center><h1>สามเณร</h1></center>
<table id="table" width="800">
<tr>
<th>ชื่อ</th>
<th>สกุล</th>
</tr>
<?
while($data3 = mysqli_fetch_array($result3))
{
?>
<tr>
<td> <?php echo $data3["name_novice"]?> </td>
<td> <?php echo $data3["lastname_novice"]?> </td>
</tr>
<?
}
?>
</table><br>
</body>
</html>
<?php
}
$mysql_close($objCon);
?>
|
|
|
|
|
Date :
2017-05-05 21:30:55 |
By :
ccjpn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|