|
 |
|
LOOP ซ้อน loop บน Table โดยดึงจาก Table บน DB 2 TABLE โดยมีเงื่อนไขดึงค่าที่ไม่เหมือนกันครับ |
|
 |
|
|
 |
 |
|
<?php
echo $sqla = "select * from stock_history where job_no ='$job_review'" ;//table1
$dbquerya = mysql_db_query($dbname, $sqla); $notIN='';
while($rowa = mysql_fetch_array($dbquerya)){
echo "<br>";
echo $st_item_name=$rowa[st_item_name];
echo "<br>";
$st_item_serial=$rowa[st_item_serial];
$notIN .= ($notIN? ', ' : '') . " '$st_item_name' ";
?>
<tr>
<td align="left" class="TFChiangsaen"><? echo $st_item_name; ?></td>
<td align="right" class="TFChiangsaen"><? echo $st_item_serial; ?></td>
</tr>
<? echo $sql = "select * from stock where job_no ='$job_review' and st_name not in ( $notIN) "; //table2
}
$dbquery = mysql_db_query($dbname, $sql);
while($row = mysql_fetch_array($dbquery)){
echo "<br>";
echo $st_name=$row[st_name];
//
$st_piece=$row[st_piece];
?>
<tr>
<td align="left" class="TFChiangsaen"><? echo $st_name; ?></td>
<td align="right" class="TFChiangsaen"><? echo $st_piece." "."(UNIT)"; ?></td>
</tr>
<?
}
?>
|
 |
 |
 |
 |
Date :
2014-08-20 07:07:48 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพิ่มเติมครับ
SQL :: Table#2
Code (PHP)
SELECT * FROM stock
WHERE job_no = '$job_review'
AND st_name NOT IN (SELECT st_item_name FROM stock_history GROUP BY st_item_name)
|
 |
 |
 |
 |
Date :
2014-08-20 08:18:35 |
By :
fossil31 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ลองดูตัวอย่างที่ผมทำให้ จะแก้ส่วนไหนก็ลองดูครับ
|
 |
 |
 |
 |
Date :
2014-08-20 08:20:21 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ คิดตกมะคืนตีสาม 555 ขอบคุนมากๆครับ
Code (PHP)
<? $sqla = "select pp.st_item_name,pp.st_item_serial from stock_history pp
where pp.st_item_name in (select j.st_name from stock j)
and pp.job_no ='$job_review'" ;
$dbquerya = mysql_db_query($dbname,$sqla);
while($rowa = mysql_fetch_array($dbquerya)){
$st_item_name=$rowa[st_item_name];
$st_item_serial=$rowa[st_item_serial];
?>
<tr>
<td align="left" class="TFChiangsaen"><? echo $st_item_name; ?></td>
<td align="right" class="TFChiangsaen"><? echo $st_item_serial; ?></td>
</tr>
<? }?>
<? $sqlb = "select j.st_name,j.st_piece from stock j
where j.st_name not in (select pp.`st_item_name` from stock_history pp )
and j.job_no ='$job_review'" ;
$dbqueryb = mysql_db_query($dbname,$sqlb);
while($rowb = mysql_fetch_array($dbqueryb)){
$st_name=$rowb[st_name];
$st_piece=$rowb[st_piece];
?>
<tr>
<td align="left" class="TFChiangsaen"><? echo $st_name; ?></td>
<td align="right" class="TFChiangsaen"><? echo $st_piece." "."(UNIT)"; ?></td>
</tr>
<? } ?>
ผลลัพท์ก้เหมือนกันใช่ปะครับ
|
 |
 |
 |
 |
Date :
2014-08-20 09:07:21 |
By :
wahahaboy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|