<?php
include 'connect.php';
$sql .="(SELECT * FROM tbl_ability where type_id='1' AND member_id='mem_001') AS lang ";
$sql .="(SELECT * FROM tbl_ability where type_id='2' AND member_id='mem_001') AS sport ";
$sql .="(SELECT * FROM tbl_ability where type_id='3' AND member_id='mem_001') AS art ";
$sql .="(SELECT * FROM tbl_ability where type_id='4' AND member_id='mem_001') AS computer ";
$query=mysqli_multi_query($con,$sql);
?>
<br/>
<h5 align="center">ตารางแสดงข้อมูลความสามรถพิเศษ</h5>
<tr>
<th>ภาษา</th>
<th>กีฬา</th>
<th>ศิลปะ/ดนตรี</th>
<th>คอมพิวเตอร์</th>
</tr>
<?php
while($row=mysqli_fetch_array($query)){
?>
<tr>
<td><?=$row['lang '];?></td>
<td><?=$row['sport '];?></td>
<td><?=$row['art '];?></td>
<td><?=$row['computer '];?></td>
</tr>
<?php } ?>
<?php
///$profile = 0001
$sql .="SELECT ability_name AS a FROM tb_ability where type_id='1'AND id_card='$profile'";
$sql .="SELECT ability_name AS b FROM tb_ability where type_id='2' AND id_card='$profile'";
//$sql .="SELECT * FROM tbl_ability where type_id='3' AND id_card='$profile'";
//$sql .="SELECT * FROM tbl_ability where type_id='4' AND id_card='$profile'";
$query_ability=mysqli_multi_query($con,$sql);
while($result_ability=mysqli_fetch_array($query_ability)){
?>
<tr>
<td><?=$result_ability['a'];?></td>
<td><?=$result_ability['b'];?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<?php } ?>
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT ability_name AS b FROM tb_ability where type_id='2' AND id_card='2db85...' at line 1
msg ที่แจ้งครับ
ส่วนเรื่อง ; แบบนี้ใช่ไหมครับ
$sql ="SELECT ability_name AS a FROM tb_ability where type_id='1'AND id_card='$profile';";
$sql .="SELECT ability_name AS b FROM tb_ability where type_id='2'AND id_card='$profile'";
$query_ability=mysqli_multi_query($con,$sql) or die(print_r($con->error, true));
ลอง ใช้ next result ละครับ ทำไมข้อมูลมันถึงไม่เรียงลำดับตามที่ต้องการครับ ผมใส่ loop ผิดหรือเปล่าครับ รบกวนหน่อยครับ
Code (PHP)
<table id="ability_table" class="table table-bordered display nowrap" style="width:100%">
<thead class="thead-dark">
<br/>
<h5 align="center">ตารางแสดงข้อมูลความสามรถพิเศษ</h5>
<tr>
<th>ภาษา</th>
<th>กีฬา</th>
<th>คอมพิวเตอร์</th>
<th>ศิลปะ/ดนตรี</th>
<th>ออกแบบ/ตัดต่อ</th>
<th>ยุทธวิธี</th>
<th>อื่นๆ</th>
</tr>
</thead>
<tbody>
<?php
$sql ="SELECT ability_name AS lang FROM tb_ability where type_id='1'AND id_card='2db85708fc455aa574d5b15ad8fef134';";
$sql .="SELECT ability_name AS sport FROM tb_ability where type_id='2' AND id_card='2db85708fc455aa574d5b15ad8fef134';";
$sql .="SELECT ability_name AS com FROM tb_ability where type_id='4' AND id_card='2db85708fc455aa574d5b15ad8fef134';";
$sql .="SELECT ability_name AS art FROM tb_ability where type_id='3' AND id_card='2db85708fc455aa574d5b15ad8fef134';";
$sql .="SELECT ability_name AS design FROM tb_ability where type_id='5'AND id_card='2db85708fc455aa574d5b15ad8fef134';";
$sql .="SELECT ability_name AS tactic FROM tb_ability where type_id='6'AND id_card='2db85708fc455aa574d5b15ad8fef134';";
$sql .="SELECT ability_name AS etc FROM tb_ability where type_id='7' AND id_card='2db85708fc455aa574d5b15ad8fef134'";
// Execute multi query
if (mysqli_multi_query($con, $sql)) {
do {
// Store first result set
if ($result = mysqli_store_result($con)) {
while ($row = mysqli_fetch_assoc($result)) {
?>
<tr>
<td><?=$row['lang'];?></td>
<td><?=$row['sport'];?></td>
<td><?=$row['com'];?></td>
<td><?=$row['art'];?></td>
<td><?=$row['design'];?></td>
<td><?=$row['tactic'];?></td>
<td><?=$row['etc'];?></td>
</tr>
<?php
}
mysqli_free_result($result);
}
} while (mysqli_next_result($con));
} ?>