|
|
|
สอบถาม SQL ที่ใช้สำหรับ Query ข้อมูลออกเป็นคอลัมน์ |
|
|
|
|
|
|
|
แบบนี้เลย ง่ายดี 5555555
Code (PHP)
$objConnect = mysql_connect("localhost","root","pass") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM Query WHERE product='กระเป๋า' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
echo $objResult['product'].' | '.$objResult['amount'];
while($objResult = mysql_fetch_array($objQuery))
{
echo ' | '.$objResult['amount'];
}
|
|
|
|
|
Date :
2020-01-06 20:44:20 |
By :
maxvit |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
group_concat + explode + implode
Code (SQL)
select product , group_concat(id,',') as gID from table where xxx group by product
Code (PHP)
while ( $ro = $result->fetch_object()){
$id_list=explode(',',$ro);
?>
<tr>
<td><?=$ro->product?></td>
<td><?=implode('</td><td>', $id_list)?></td>
</tr>
<?php }
|
|
|
|
|
Date :
2020-01-07 09:26:33 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|