請問,我想在這個表單,帶入其他的資料表,然後又要比對某一個欄位,要怎麼做呢?(超新手,真的想很久了)

如提:以下是我的表單程式碼
<?
require "setup.php";
$link=mysql_connect($DB_SERVER,$DB_USER,$DB_PASS);
mysql_select_db($DB_NAME,$link);

//計算筆數
$str="select count(*) from $Sales_details";
$list =mysql_query($str,$link);
list($public_count) = mysql_fetch_row($list);

?>

<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=utf8">
<html>
<head>
<title>全部資料</title>
<script language="JavaScript" src="chk_data.js"></script>
<link rel="stylesheet" type="text/css" title="Style" href="classweb.css">
</head>

<body background="../images/back_right.jpg">
<center>
<a href="../images/public.php" target="_blank">
<font color=blue size=10 face=標楷體><b>銷售成本分析表</b></font></a>

<form action="search.php" method="post">
請輸入關鍵字:<input type="text" name="key_word">
<input type="submit" value="搜尋">
</form>
<P>
本區共有<font face="Arial" color="Red">
<?echo $public_count;?></font>筆銷售成本,
請選擇頁數<font face="Arial Black"> |

<?
//抓取頁數
$page_num=$_GET["page_num"];
$all_page=ceil($public_count/$read_num);
for($i=1;$i<=$all_page;$i++){
  echo "<a href='index_pub.php?page_num=$i'><font color='blue'> $i </font></a>|";
  }
?>
</font>

<P>
排列方式:
 | <a href="index_pub.php?sort=id ASC">
 <font color='blue'>編號小到大</font></a>
 | <a href="index_pub.php?sort=id desc">
 <font color='blue'>編號大到小</font></a> |

<table width="1400" border="1" style="border-collapse: collapse" align= "center" bgcolor="DarkOrange">
<tr align="center" bgcolor=BurlyWood>
<td align="center">編號</td>
<td align="center">銷退貨日期</td>
<td align="center">銷退貨單號</td>
<td align="center">客戶簡稱</td>
<td align="center">品號</td>
<td align="center">品名</td>
<td align="center">倉庫</td>
<td align="center">數量</td>
<td align="center">單位</td>
<td align="center">單價</td>
<td align="center">金額</td>
<td align="center">負責業務</td>
<td align="center">成本</td>
<td align="center">毛利</td>
</tr>
<?
$link=mysql_connect($DB_SERVER,$DB_USER,$DB_PASS);
mysql_select_db($DB_NAME,$link);

//排序預設值
$sort=$_GET["sort"];
if(empty($sort))$sort="id asc";

//分頁分析
if(empty($page_num))$page_num="1";
$start_num=$read_num*($page_num-1);
$str="select id,Sales_date,Sales_slip_number,Customer,Product_No,Product_Name,
warehouse,amount,unit,unit_price,Money,sales from Sales_details
 order by $sort limit $start_num,$read_num";
$list =mysql_query($str,$link);

while(list($id,$Sales_date,$Sales_slip_number,$Customer,$Product_No,$Product_Name,$warehouse,$amount,
$unit,$unit_price,$Money,$sales) = mysql_fetch_row($list)){

if(strlen($Customer)>40){
        $Customer=substr($Customer,0,40)."-----";
}

if($close_html){
        $id=htmlspecialchars($id);
        $Sales_date=htmlspecialchars($Sales_date);
        $Sales_slip_number=htmlspecialchars($Sales_slip_number);
		$Customer=htmlspecialchars($Customer);
		$Product_No=htmlspecialchars($Product_No);
		$Product_Name=htmlspecialchars($Product_Name);
		$warehouse=htmlspecialchars($warehouse);
		$amount=htmlspecialchars($amount);
		$unit=htmlspecialchars($unit);
		$unit_price=htmlspecialchars($unit_price);
		$Money=htmlspecialchars($Money);
		$sales=htmlspecialchars($sales);
//		$=htmlspecialchars($);
//		$=htmlspecialchars($);
}

if(++$public_count % 2 > 0){
    $bgcolor="PaleGreen";
}
else{
     $bgcolor="LemonChiffon";
}

echo "<tr bgcolor='$bgcolor'>
       <td nowrap><font color='coral'>$id</font></td>
       <td><a href='view_pub.php?id=$id'>
       <font color='blue'>$Sales_date</font></a></td>
       <td><a href='view_pub.php?id=$Sales_date'>
	   <font color='green'>$Sales_slip_number</font></a></td>
       <td align='center'>
	   <font color='red'>$Customer</font></td>
	   <td align='center'>
	   <font color='blue'>$Product_No</font></td>
	   <td align='center'>
	   <font color='blue'>$Product_Name</font></td>
	   <td align='center'>
	   <font color='green'>$warehouse</font></td>
	   <td align='center'>
	   <font color='green'>$amount</font></td>
	   <td align='center'>
	   <font color='black'>$unit</font></td>
	   <td align='center'>
	   <font color='red'>$unit_price</font></td>
	   <td align='center'>
	   <font color='red'>$Money</font></td>
	   <td align='center'>
	   <font color='blue'>$sales</font></td>
	   <td align='center'>
	   <font color='blue'>$</font></td>
	   <td align='center'>
	   <font color='blue'>$</font></td></tr>";
}
mysql_close($link);
?>
</table>
<form action="webmaster.php" method="post">
站長管理帳號:<input type="text" name="root_name" size="10">
密碼:<input type="password" name="root_password" size="10">
<input type="submit" value="登入">
</form>

</center>
</body>
</html>
其中的成本&毛利小弟想帶入Purchase_Order資料表中的unit_price欄位&Money欄位,又必須要對應 Sales_details資料表的Product_No欄位,資料才會正確,請問該如何做呢?

附上setup.php
<?
//資料庫連結網址:
$DB_SERVER="localhost";

//資料庫名稱:
$DB_NAME="PD";

//資料庫帳號:
$DB_USER="root";

//資料庫密碼:
$DB_PASS="Ahda1722";

//表單名稱名稱
$Sales_details="Sales_details";

//表單名稱
$Purchase_Order="Purchase_Order";

//HTML開關(1關閉、0打開)
$close_html=1;

//每頁顯示的筆數
$read_num="30";

?>

附上資料庫
/*
Navicat MySQL Data Transfer

Source Server         : --
Source Server Version : 50549
Source Host           : --
Source Database       : PD

Target Server Type    : MYSQL
Target Server Version : 50549
File Encoding         : 65001

Date: 2016-08-04 11:24:26
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for `Purchase_Order`
-- ----------------------------
DROP TABLE IF EXISTS `Purchase_Order`;
CREATE TABLE `Purchase_Order` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `Purchase_date` text NOT NULL,
  `Purchase_number` text NOT NULL,
  `Customer` text NOT NULL,
  `Product_No` varchar(255) NOT NULL,
  `Product_Name` text NOT NULL,
  `amount` text NOT NULL,
  `unit` text NOT NULL,
  `unit_price` text NOT NULL,
  `Money` text NOT NULL,
  PRIMARY KEY (`Product_No`,`id`)
) ENGINE=MyISAM AUTO_INCREMENT=276 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of Purchase_Order
-- ----------------------------
-- ----------------------------
-- Table structure for `Sales_details`
-- ----------------------------
DROP TABLE IF EXISTS `Sales_details`;
CREATE TABLE `Sales_details` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `Sales_date` text NOT NULL,
  `Sales_slip_number` text NOT NULL,
  `Customer` text NOT NULL,
  `Product_No` varchar(255) NOT NULL,
  `Product_Name` text NOT NULL,
  `warehouse` text NOT NULL,
  `amount` text NOT NULL,
  `unit` text NOT NULL,
  `unit_price` text NOT NULL,
  `Money` text NOT NULL,
  `sales` text NOT NULL,
  PRIMARY KEY (`Product_No`,`id`)
) ENGINE=MyISAM AUTO_INCREMENT=66 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;


請各位大大幫忙協助解惑,再麻煩各位了,thanks~~~

評論

Sign In or Register to comment.