我在PHP和SQL方面非常新颖,所以我正在对着墙壁敲打我的头,以了解如何让它达到我期待的结果。我正在研究产品库存网站。该网站允许您输入收到的订单/数量,并更新特定产品的总量。乘以2个不同表格的值
有一个“交易”表;如接收更多产品和“产品”表格。
我试图用产品的单位价格乘以该产品的单位价格,以便它显示在该产品线上投入的总金额。
这里是我使用的代码 - 交易表是site_trans和产品的表格是site_products:
<form>
<title>Products List</title>
<border>true</border>
<width>580</width>
<fields>
<_count header="No" suffix="." width="25" align="center" />
<product_name align="left" header="Name" />
<product_number align="center" header="Number" />
<product_count align="center" type="sql" header="Count">
<sql>
<vars>
<table import="$this->tables[transactions]" type="eval" />
<product import="product_id" type="field" />
</vars>
<query>SELECT sum(trans_inventory) FROM {TABLE} WHERE trans_product='{PRODUCT}'</query>
<field>sum(trans_inventory)</field>
</sql>
</product_count>
<product_cost align="center" header="Cost" />
<product_uom align="center" header="Unit" />
<product_totcost align="center" type="sql" header="Total">
<sql>
<vars>
<table import="$this->tables[transactions]" type="eval" />
<prodcost import="product_cost" type="field" />
</vars>
<query>SELECT sum(trans_inventory), sum('{PRODCOST}') FROM site_trans, site_products WHERE trans_product=product_id</query>
<field>sum(trans_inventory*product_cost)</field>
</sql>
</product_totcost>
</fields>
<header>
<titles>true</titles>
<buttons>
<export onclick="" button="export">
<location>index.php?sub=export&action=products</location>
</export>
<add button="addnew">
<location>index.php?sub=products&action=add&returnurl={CURRENT_PAGE}</location>
</add>
</buttons>
</header>
<buttons>
<delete onclick="" button="delete" >
<location>javascript:if(confirm('Are you sure you want to delete this record ?')) window.location='index.php?sub=products&action=delete&product_id={PRODUCT_ID}&returnURL={CURRENT_PAGE}'</location>
</delete>
<details onclick="" button="details" >
<location>index.php?sub=products&action=details§ion=1&product_id={PRODUCT_ID}&returnurl={CURRENT_PAGE}</location>
</details>
</buttons>
<items>25</items>
那是给我的问题代码的特定部分是这样的:
<product_totcost align="center" type="sql" header="Total">
<sql>
<vars>
<table import="$this->tables[transactions]" type="eval" />
<prodcost import="product_cost" type="field" />
</vars>
<query>SELECT sum(trans_inventory), sum('{PRODCOST}') FROM site_trans, site_products WHERE trans_product=product_id</query>
<field>sum(trans_inventory*product_cost)</field>
</sql>
</product_totcost>
请帮助! :)
要添加到此;这里是事务代码(add.xml),用于更新site_trans数据库中每个产品的数量。也许这个代码将一些线索,我们错过了什么(我不知道)
<form>
<title>{PRIVATE.FORM_ACTION_TITLE} Transaction</title>
<action>index.php?sub=transactions&action=store</action>
<name>edit</name>
<width>580</width>
<formtag>true</formtag>
<border>true</border>
<buttons>
<set>
<footer>true</footer>
<header>true</header>
</set>
<return onclick="" button="return">
<location>{PRIVATE.FORM_PREVIOUS_PAGE}</location>
</return>
<save onclick="" button="saveall">
<location>javascript:document.forms[0].submit();</location>
</save>
</buttons>
<redirect>index.php?sub=accounts</redirect>
<fields>
<trans_id type="hidden" hidden="true"/>
<trans_date type="hidden" default="time()" action="eval"/>
<trans_user type="hidden" default="$_SESSION[minibase][raw][user_id]" action="eval"/>
<trans_post_ip type="hidden" default="$_SERVER[REMOTE_ADDR]" action="eval"/>
<trans_relation type="hidden" default="$_GET[trans_relation]" action="eval"/>
<trans_product type="hidden" default="$_GET[trans_relation]" action="eval"/>
<trans_inventory type="textbox" size="5" required="true" validate="A:2:200">
<title>Inventory</title>
<description>Box to either add (+40) or remove inventory (-40).</description>
</trans_inventory>
<trans_date2 type="date" now="true">
<title>Date</title>
<fields>
<month format="int" default="now" />
<day format="int" default="now" />
<year from="2011" to="2110" default="now"/>
</fields>
</trans_date2>
<trans_description type="textarea" size="60:4">
<title>Description</title>
</trans_description>
</fields>
Wbat语言/模板语言是这样吗? :S – Nick 2011-04-03 21:32:12
php我认为。大部分代码都是免费的,我试图修改它以适应我需要的功能。不幸的是,我不确定我知道如何回答你的问题,因为我对SQL和PHP很陌生。在编码中有什么会告诉我你在问什么?或者我回答了吗?大声笑 – 2011-04-04 03:27:15
其实,我很抱歉。这是一个xml文件的一部分。 – 2011-04-04 03:29:50