|
 |
|
ช่วยดูโค้ด การเอาข้อมูลมาจาก ตารางดาต้าเบส 2 ตารางเพื่อเอามาเปรียบข้อมูล |
|
 |
|
|
 |
 |
|
รบกวนผู้รู้ช่วยหน่อยนะครับจากโค้ดข้างล่างเป็นเพียงการเปรียบเทียบแค่ข้อมูลที่มีอยู่ไม่ได้เอามาจาก ตาราง ผมมาถูกทางหรือยังพอจะทำได้ไหมหรือว่าต้องทำยังไงครับ ขอบคุณครับ(มือใหม่ครับ)
Code (PHP)
<?php require_once('./Connections/db_conn.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<?php
mysql_connect($hostname_db_conn,$username_db_conn,$password_db_conn);
mysql_select_db($database_db_conn);
mysql_query('SET CHARACTER SET utf8');
$seta = array("ram","mouse","keyboard","vga","nvidia","intel"); // เปลี่ยนแค่ข้อมูลตรงนี้คือเอามาจาก table 1
$setb = array("ram","vga","intel","mouse","LCD","keyboard"); // เปลี่ยนข้อมูลตรงนี้คือเอามาจาก table 2
$result_of_new = new_value($seta,$setb);
$result_of_intersect = intersect_value($seta,$setb);
$result_of_lost = lost_value($seta,$setb);
echo '<pre>';
echo "ข้อมูลที่เข้ามาใหม่ ";
print_r($result_of_new);
echo "ข้อมูลที่มีเหมือนกัน";
print_r($result_of_intersect);
echo "ข้อมูลที่มีไม่เหมือนกัน";
print_r($result_of_lost);
echo '</pre>';
function new_value($old,$new){
$temp = array();
$hit = false;
foreach ($new as $ni => $nvalue) {
$hit = false;
foreach ($old as $oi => $ovalue) {
if( $nvalue == $ovalue ){
$hit = true;
}
}
if($hit == false){
array_push($temp, $nvalue);
}
}
return $temp;
}
function intersect_value($old,$new){
$temp = array();
$hit = false;
foreach ($new as $ni => $nvalue) {
$hit = false;
foreach ($old as $oi => $ovalue) {
if( $nvalue == $ovalue ){
$hit = true;
}
}
if($hit == true){
array_push($temp, $nvalue);
}
}
return $temp;
}
function lost_value($old,$new){
$temp = array();
$hit = false;
foreach ($old as $oi => $ovalue) {
$hit = false;
foreach ($new as $ni => $nvalue) {
if( $nvalue == $ovalue ){
$hit = true;
}
}
if($hit == false){
array_push($temp, $ovalue);
}
}
return $temp;
}
?>
</body>
</html>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2011-05-24 09:03:45 |
By :
nano |
View :
879 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมอยากได้ โค้ดวิธีเพื่อนำตาราง2 ตารงมาเปรียบเทียบข้อมูลกันครับ
|
 |
 |
 |
 |
Date :
2011-05-24 09:28:29 |
By :
nano |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|