不寻常的查询帮助请求 [英] Unusual Query Help Request
问题描述
我有一个查询,我试图使用php和mysql从3个不同的
表中提取数据。我原本希望有一个唯一的标识符
来帮助确保参照完整性,但似乎唯一的数字
不会总是有可能所以我不会银行在它上面。
我在这两个表''area''和''equipment''中有两个相似的字段和
虽然有一个在同一件事所称的两个区域内有两件不同的b / b $ b设备的可能性,如果我可以链接的话,有两件设备叫做同样的设备的可能性是多少? br />
到那个''区域'列是不可能的,因此我唯一的身份
以下是我现有的代码看起来有效,但没有链接
'设备'列中表格的区域列。在几次输入数据库之前,没有注意到
问题。现在我可以看到我必须将各个表中的两列链接起来,以便为这三个表中的特定表行形成一个唯一的
标识符。
------------------------------------------
<?php
require_once(''generic_connect.php'');
$ DBname =" Equipment";
$ area = $ _POST [''area''];
mysql_connect($ DBhost,$ DBuser,$ DBpass)或死亡(无法连接到
主机$ DBhost");
mysql_select_db($ DBname)或死(无法选择数据库$ DBname);
$ query =" SELECT conveyors.equipname,conveyors.equipno,
conveyorors.mcc,conveyors.gb,conveyors.lube,conveyors.gbsize,
输送机.brgtype,conveyors.brgqty,motors.hp,motors.frame,
motors.amps,motors.rpm,equipcontacts.equipmanu,
equipcontacts.smodel,equipcontacts.sserial ,equipcontacts.vendphone
FROM输送机,电机,设备接触
WHERE conveyors.equipname = motors.equipname和
conveyors.equipname = equipcontacts.equipname" ;;
if($ area!=" All")$ query。=" and(conveyors.area =''$ area''或
motors.area =''$ area' '或equipcontacts.area =''$ area'')" ;;
$ result = mysql_query($ query);
--------- -------------------------
我希望链接每个表中的两列可能
简单如下:
WHERE conveyors.area.equipname = motors.area.equipname和
conveyors.area.equipname = equipcontacts。 area.equipname" ;;
但没有这样的运气。我的桌子是''传送带'',''马达''和
''equipcontacts''。
感谢任何回复。
cov
I have a query where I''m attempting to pull data from 3 different
tables using php and mysql. I had hoped to have a unique identifier
to help ensure referential integrity but it appears that unique number
won''t always be a possibility so I won''t bank on it at all.
I have two like fields in these two tables ''area'' and ''equipment'' and
though there is a possibility of having two different pieces of
equipment within two areas called by the same thing, the possibility
of having two pieces of equipment called the same thing if I can link
to that ''area'' column is impossible, hence my unique id
Below is what my existing code looks like that works but doesn''t link
the ''area'' column of a table to the ''equipment'' column. Didn''t notice
a problem until several entries to the db. Now I can see that I must
link the two columns within the individual tables to form a unique
identifier for those particular table rows within the three tables.
------------------------------------------
<?php
require_once(''generic_connect.php'');
$DBname = "Equipment";
$area = $_POST[''area''];
mysql_connect($DBhost, $DBuser, $DBpass) or die("Unable to connect to
host $DBhost");
mysql_select_db($DBname) or die("Unable to select database $DBname");
$query = "SELECT conveyors.equipname, conveyors.equipno,
conveyors.mcc, conveyors.gb, conveyors.lube, conveyors.gbsize,
conveyors.brgtype, conveyors.brgqty, motors.hp, motors.frame,
motors.amps, motors.rpm, equipcontacts.equipmanu,
equipcontacts.smodel, equipcontacts.sserial, equipcontacts.vendphone
FROM conveyors, motors, equipcontacts
WHERE conveyors.equipname = motors.equipname and
conveyors.equipname = equipcontacts.equipname ";
if ($area != "All") $query .= "and (conveyors.area=''$area'' or
motors.area=''$area'' or equipcontacts.area=''$area'')";
$result = mysql_query($query);
----------------------------------
I would have hoped that linking the two columns within each table may
be as simple as:
WHERE conveyors.area.equipname = motors.area.equipname and
conveyors.area.equipname = equipcontacts.area.equipname ";
but no such luck. My tables are ''conveyors'', ''motors'' and
''equipcontacts''.
thanks for any replies.
cov
推荐答案
DBname =" Equipment";
DBname = "Equipment";
area =
_POST [''area''];
mysql_connect(
_POST[''area''];
mysql_connect(
这篇关于不寻常的查询帮助请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!