 |
|
คือเวลาเปรียบเทียบข้อมูลตารางหนึ่งกับตารางสองตารางอ่ะครับ
ให้แสดงข้อมูลที่ตารางหนึ่งมีในตารางสอง และ ข้อมูลที่ในตารางหนึ่งไม่มีในตารางสอง
แต่พอรันแล้วข้อมูลที่ในตารางหนึ่งไม่มีในตารางสองมันแสดงออกมาหมดเลยครับ
ทำยังไงถึงจะให้มันแสดงตามเงื่อนไขอ่ะครับ
โค้ดครับ
<body>
<?php
set_time_limit(0);
$link= mysql_connect(localhost,root,240730);
if(!$link)
{
print("<b>Can't connect to host</b>");
}
else
{
print("<b>OK!!!</b><br>");
mysql_select_db("tot",$link) or die ("Can't connect to data base");
mysql_query( "set character_set_results=tis620 ");
mysql_query( "set character_set_connection=tis620 ");
mysql_query( "set character_set_client=tis620 ");
$result=mysql_query("SELECT r.tel, r.name, r.rcu, r.date, r.usage, r.service, r.tax, r.total, count(r.tel) other
FROM tttt as r RIGHT JOIN test as t
ON t.tel=r.telnew
GROUP BY r.tel, r.name, r.rcu, r.date, r.usage, r.service, r.tax, r.total" ,$link);
$num=mysql_num_rows($result);
$num2=$num-1;
print("ตรงกัน=$num2<br>");
while($row=mysql_fetch_row($result))
{
print("$row[0] _____ $row[1] _____$row[2]_____$row[3]_____$row[4]_____$row[5]_____$row[6]_____ $row[7]_____$row[8] <br>");
}
$result1=mysql_query("SELECT t.tel, t.code1, t.d, t.code2, t.f, t.where, count(t.tel) other
FROM tttt as r, test as t
WHERE not t.tel = r.telnew
GROUP BY t.tel, t.code1, t.d, t.code2, t.f, t.where",$link);
$num1=mysql_num_rows($result1);
print("ไม่ตรงกัน=$num1<br>");
while($row1=mysql_fetch_row($result1))
{
print("$row1[0] _____ $row1[1] $row1[2]_____$row1[3]$row1[4]_____$row1[5]_____$row1[6] <br>");
}
echo mysql_error();
mysql_close($link);
}
?>
</body>
อันนี้ตัวอย่างผลครับ
ตรงกัน=5
_____ ______________________________ _____0
7671924 _____ ถนนสาธรใต้ _____TMM_____20060516_____3399_____3176.64_____222.36_____ 3399_____1
7677932 _____ ถนนสาธรใต้ _____TMM_____20060516_____4429_____4139.25_____289.75_____ 4429_____1
8002130 _____ ถนนสาธรใต้ _____TMM_____20060516_____169_____157.94_____11.06_____ 169_____1
8002462 _____ ถนนสาธรใต้ _____TMM_____20060516_____906_____846.73_____59.27_____ 906_____1
8002471 _____ ถนนสาธรใต้ _____TMM_____20060516_____593_____554.21_____38.79_____ 593_____1
ไม่ตรงกัน=10
27671924 _____ ROTOR 1 PLUS _____WR020C-0409_____เยื้อง LOTUS ซ.เพชรเกษม 110_____9
27677932 _____ L _____WR020-4882L_____หน้าวัดไผ่เลี้ยง ซอยเพชรเกษม 110_____9
28002130 _____ _____WR090-5434_____ในซอยตรงข้าม ม.มหิดล_____9
28002462 _____ _____WR090-6114_____ตรงข้าม ม.มหิดล_____9
28002471 _____ _____WR090-6108_____ข้างป้อมตำรวจตรงข้ามทางเข้า ม.มหิดล ศาลายา_____9
28002491 _____ _____WR090-6109_____ข้างป้อมตำรวจตรงข้ามทางเข้า ม.มหิดล ศาลายา_____10
28002581 _____ _____WR090-8895_____หน้าธนาคารไทยพาณิชย์ ตรงข้าม ม.มหิดล_____10
28002605 _____ _____WR090-2553_____ในซอยพูลทรัพย์ ถ.ศาลายา_____10
28002607 _____ _____WR090-7368_____หน้าเขตทวีวัฒนาเก่า ถ.บรมฯ_____10
28002621 _____ _____WR090-6128_____ตรงข้าม ม.มหิดล_____10
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
17 เม.ย. 2551 11:53:53 |
By :
ฝึกหัด |
View :
1173 |
Reply :
0 |
|
 |
 |
 |
 |
|
|
|
 |