473,511 Members | 15,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unusual Query of three tables

cov
I have a php query where I'm attempting to pull data from 3 different
tables between a php form and mysql db. I had hoped early on to use a
unique identifier to help ensure referential integrity between table
data but it appears that unique number isn't viable so I going a
different route.

I have two similar columns in these tables 'area' and 'equipment' that
I'd like to use as the unique identifier (when used together ) since
though there is a possibility of having two different pieces of
equipment within two different areas named by the same thing, the
possibility of having two pieces of equipment named the same thing
within two diffent areas won't happen SO if I can link the 'area'
column with 'equpment', I'll have 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 columns within the different
three tables of the db.

<?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
cov
Nov 10 '07 #1
7 1681
cov wrote:
I have a php query where I'm attempting to pull data from 3 different
tables between a php form and mysql db. I had hoped early on to use a
unique identifier to help ensure referential integrity between table
data but it appears that unique number isn't viable so I going a
different route.

I have two similar columns in these tables 'area' and 'equipment' that
I'd like to use as the unique identifier (when used together ) since
though there is a possibility of having two different pieces of
equipment within two different areas named by the same thing, the
possibility of having two pieces of equipment named the same thing
within two diffent areas won't happen SO if I can link the 'area'
column with 'equpment', I'll have 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 columns within the different
three tables of the db.

<?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
cov
You've already asked this in comp.databases.mysql, which is where is
should be. But you haven't responded with the information we need to
help you.

This is a straight SQL question and has nothing to do with PHP.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 10 '07 #2
cov
On Sat, 10 Nov 2007 11:39:57 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>You've already asked this in comp.databases.mysql, which is where is
should be. But you haven't responded with the information we need to
help you.
Each table has an id field that is an INT - this field auto-increments
and is the primary key field for each table. All others are varchar
25 limit w/no key set. Zero decimals and allow null not set. thanks
Nov 10 '07 #3
cov wrote:
On Sat, 10 Nov 2007 11:39:57 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>You've already asked this in comp.databases.mysql, which is where is
should be. But you haven't responded with the information we need to
help you.

Each table has an id field that is an INT - this field auto-increments
and is the primary key field for each table. All others are varchar
25 limit w/no key set. Zero decimals and allow null not set. thanks
As I said. This is not the correct newsgroup for MySQL questions.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 10 '07 #4
cov
On Sat, 10 Nov 2007 15:18:40 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>As I said. This is not the correct newsgroup for MySQL questions.
Not sure I understand why you would say that when it is php code
interfacing with mysql. The form code is all php/html so how that
query were written accordingly and interact with mysql, would
seemingly be entirely a php matter.
Nov 11 '07 #5
Greetings, cov.
In reply to Your message dated Sunday, November 11, 2007, 07:01:35,
>>As I said. This is not the correct newsgroup for MySQL questions.
Not sure I understand why you would say that when it is php code
interfacing with mysql.
Make sure You getting proper data from database before trying to use it in PHP code.
So, go to comp.database.mysql and refine Your MySQL knowledge.
(Guess You know how to use MySQL without PHP)
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Nov 11 '07 #6
cov wrote:
On Sat, 10 Nov 2007 15:18:40 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>As I said. This is not the correct newsgroup for MySQL questions.

Not sure I understand why you would say that when it is php code
interfacing with mysql. The form code is all php/html so how that
query were written accordingly and interact with mysql, would
seemingly be entirely a php matter.
Because your question is purely SQL related. There is nothing here
which is related to PHP or any other programming language.

First rule of newsgroups - determine where you problem is and post to
the appropriate newsgroup. Second rule - give enough information for
people to help you with your problem.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 11 '07 #7
BoneIdol wrote:
>
Ok I admit that I shot my mouth off regarding it only working properly
with a one-to-one relationship, but since it doesn't give any results
if a where clause isn't met it is (usually) a hinderance. Aside from
that, I feel I gave an informed and useful response, and I simply
refuse to fuel your infantile flaming.
No flaming. PHP is NOT MySQL and vice versa. There are many MySQL
experts - including people on the MySQL design team - who monitor
comp.databases.mysql. Many of them do not monitor this newsgroup.

The best place to get MySQL answers is in that group. I would say the
vast majority of the people here are amateurs with MySQL compared to the
people in that newsgroup.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 20 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2862
by: Jeremy Wallace | last post by:
I have a ton of queries that I need users to be able to view. I'd like to have them viewed in a datasheet-view form instead of directly, so that I can keep the users from futzing with the data. ...
2
4516
by: Colleyville Alan | last post by:
I want to extract some records that are common to three tables, but not contained in the fourth. Following what I have see in the archives and also trying the unmatched records query wizard, if I...
7
3641
by: RLN | last post by:
Re: Access 2000 I have three history tables. Each table contains 3 years worth of data. All three tables have a date field in them (and autonum field). Each table has the potential to contain...
8
5046
by: Matt | last post by:
Hi all, Thank you for taking the time. I have a database with 45 tables on it. 44 tables are linked to a main table through a one to one relationship. My question is, is there no way i can...
5
1825
by: Sean Byrne | last post by:
We have a Microsoft Access 2000 database consisting of 20 tables covering 20 different events. In each table, there are 3 Team members, a date of the event and several unique fields for the event,...
3
1436
by: Eagle | last post by:
Hi all, This one's drivin' me nuts. Any help would be appreciated. (Access 2000). I have 3 tables: tblTools: having the basic data of a tool and a field (txt) showing yes or no with regard to...
4
9158
by: coolhand729 | last post by:
Okay, this is not your normal two table query (at least it doesn't seem that way to me). I'm using Access 2000 on Windows XP. I have two tables in access. One is a table with addresses of club...
4
1930
by: pokerboy801 | last post by:
OK, I will try to explain this as clearly and as concise as possible. I am using Access, which has three MS Excel Linked tables, to store call center metrics for reps. My Excel workbook has three...
18
2279
by: cov | last post by:
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...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.