473,473 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Unusual Query Help Request

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
Nov 9 '07 #1
18 2275
cov wrote:
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
Table definitions would help...

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

Nov 9 '07 #2
cov
On Fri, 09 Nov 2007 16:31:09 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>Table definitions would help...
Table type is innoDB, character set is utf-u unicode, and fields are
varchar. Each table the same where 'type' is concerned and 'area' is
always the column next to 'equipment'. Table's were originated using
default settings with phpMyAdmin 2.6.2 thanks
Nov 10 '07 #3
cov wrote:
On Fri, 09 Nov 2007 16:31:09 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>Table definitions would help...

Table type is innoDB, character set is utf-u unicode, and fields are
varchar. Each table the same where 'type' is concerned and 'area' is
always the column next to 'equipment'. Table's were originated using
default settings with phpMyAdmin 2.6.2 thanks
He meant what are the column names in the tables... along with the
datatype of each column (describe <tablename)
Nov 10 '07 #4
cov
On Fri, 09 Nov 2007 22:20:38 -0600, Michael Austin
<no******@thistime.infwrote:

>He meant what are the column names in the tables... along with the
datatype of each column (describe <tablename)

Ahh, thanks... :-)

table names are 'conveyors', 'motors', 'equipcontacts'
Nov 10 '07 #5
cov wrote:
On Fri, 09 Nov 2007 16:31:09 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>Table definitions would help...

Table type is innoDB, character set is utf-u unicode, and fields are
varchar. Each table the same where 'type' is concerned and 'area' is
always the column next to 'equipment'. Table's were originated using
default settings with phpMyAdmin 2.6.2 thanks
Which isn't your table definitions, and tells me absolutely nothing
about your problem.

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

Nov 10 '07 #6
cov wrote:
On Fri, 09 Nov 2007 22:20:38 -0600, Michael Austin
<no******@thistime.infwrote:

>He meant what are the column names in the tables... along with the
datatype of each column (describe <tablename)


Ahh, thanks... :-)

table names are 'conveyors', 'motors', 'equipcontacts'
Which still tells me nothing...

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

Nov 10 '07 #7
cov
On Sat, 10 Nov 2007 00:01:21 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>cov wrote:
>On Fri, 09 Nov 2007 16:31:09 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>>Table definitions would help...

Table type is innoDB, character set is utf-u unicode, and fields are
varchar. Each table the same where 'type' is concerned and 'area' is
always the column next to 'equipment'. Table's were originated using
default settings with phpMyAdmin 2.6.2 thanks

Which isn't your table definitions, and tells me absolutely nothing
about your problem.
Perhaps you could help. How might I find the table definitions?
Nov 10 '07 #8
On Sat, 10 Nov 2007 07:43:13 +0100, cov <co************@yahoo.comwrote:
On Sat, 10 Nov 2007 00:01:21 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>cov wrote:
>>On Fri, 09 Nov 2007 16:31:09 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:

Table definitions would help...

Table type is innoDB, character set is utf-u unicode, and fields are
varchar. Each table the same where 'type' is concerned and 'area' is
always the column next to 'equipment'. Table's were originated using
default settings with phpMyAdmin 2.6.2 thanks

Which isn't your table definitions, and tells me absolutely nothing
about your problem.

Perhaps you could help. How might I find the table definitions?
DESCRIBE tablename;
--
Rik Wasmus
Nov 10 '07 #9
cov
On Sat, 10 Nov 2007 18:13:17 +0100, "Rik Wasmus"
<lu************@hotmail.comwrote:

>DESCRIBE tablename;
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 other key set. Zero decimals and allow null not set.
thanks
Nov 10 '07 #10
cov wrote:
On Sat, 10 Nov 2007 18:13:17 +0100, "Rik Wasmus"
<lu************@hotmail.comwrote:

>DESCRIBE tablename;

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 other key set. Zero decimals and allow null not set.
thanks
No, issue the DESCRIBE command for each table and paste the output here.

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

Nov 10 '07 #11
Jerry Stuckle <js*******@attglobal.netwrote in
news:57******************************@comcast.com:
>
No, issue the DESCRIBE command for each table and paste the output here.
REDUNDANCY is the best way to teach idiots.
REDUNDANCY is the best way to teach idiots.
REDUNDANCY is the best way to teach idiots.
REDUNDANCY is the best way to teach idiots.
REDUNDANCY is the best way to teach idiots.
REDUNDANCY is the best way to teach idiots.

You can lead some folks to knowledge, but you can't always make them think.
Nov 11 '07 #12
cov
On Sun, 11 Nov 2007 00:36:17 GMT, "Ana C. Dent"
<an*******@hotmail.comwrote:
>REDUNDANCY is the best way to teach idiots.
REDUNDANCY is the best way to teach idiots.
REDUNDANCY is the best way to teach idiots.
REDUNDANCY is the best way to teach idiots.
REDUNDANCY is the best way to teach idiots.
REDUNDANCY is the best way to teach idiots.

You can lead some folks to knowledge, but you can't always make them think.
Is this ng run by a small group of 'experts' who have no tolerance for
anyone else who hasn't achieved a level of expertise or respect to be
considered part of existing prominent 'peer group'? Is a response
such as yours in any way better than the 'spam', 'trolling' etc so
often frowned upon on usenet these days? Will your flaming me in any
way achieve any positive outcome or just result in a back and forth
negative reciprocation until someone capitulates or just goes away?
If my posts seem entirely too elementary for you to the point where
they upset you, please do us both a great service and skip by onto the
higher level of posting satisfaction that brings you here in the first
place.
Nov 11 '07 #13
Ana C. Dent wrote:
Jerry Stuckle <js*******@attglobal.netwrote in
news:57******************************@comcast.com:
>No, issue the DESCRIBE command for each table and paste the output here.

REDUNDANCY is the best way to teach idiots.
REDUNDANCY is the best way to teach idiots.
REDUNDANCY is the best way to teach idiots.
REDUNDANCY is the best way to teach idiots.
REDUNDANCY is the best way to teach idiots.
REDUNDANCY is the best way to teach idiots.

You can lead some folks to knowledge, but you can't always make them think.
That was completely uncalled for. Obviously the op is not familiar with
MySQL commands. Not everyone who posts here is an expert.

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

Nov 11 '07 #14
cov
On Fri, 09 Nov 2007 16:31:09 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>Table definitions would help...
Like these, correct?
Nov 12 '07 #15
cov
On Fri, 09 Nov 2007 16:31:09 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:

>Table definitions would help...
Couldn't post the attachment directly to the group... Such as this,
correct?

http://home.nctv.com/ajns/DESCRIBE.JPG

Nov 12 '07 #16
cov wrote:
On Fri, 09 Nov 2007 16:31:09 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>Table definitions would help...

Like these, correct?
No, just copy and past the output into your message.

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

Nov 12 '07 #17
cov wrote:
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
now that we have seen you table definitions - there are several ways to
possibly concatenate the colums when doing your searches like ANSI
Standard concatenate using the double "pipe" symbol:

area.conveyors||equipname.conveyors = area.motors||equipname.motors
and area.conveyors||equipname.conveyors = area.equipcontacts ||
equipname.equipcontacts "

Also see the Mysql docs for concat statement.
Nov 12 '07 #18
cov
On Mon, 12 Nov 2007 20:28:31 GMT, Michael Austin
<no******@thistime.infwrote:

>now that we have seen you table definitions - there are several ways to
possibly concatenate the colums when doing your searches like ANSI
Standard concatenate using the double "pipe" symbol:

area.conveyors||equipname.conveyors = area.motors||equipname.motors
and area.conveyors||equipname.conveyors = area.equipcontacts ||
equipname.equipcontacts "

Also see the Mysql docs for concat statement.

Thank you very much - appreciate the help. :-)
Nov 16 '07 #19

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

Similar topics

29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
3
by: Farooq Khan | last post by:
why does Response.Write in a method of code-beind class when called from inpage code (i.e in <%---%>), after creating object of that class, fails when called while it works perfectly ok while...
9
by: Mark | last post by:
I've run a few simple tests looking at how query string encoding/decoding gets handled in asp.net, and it seems like the situation is even messier than it was in asp... Can't say I think much of the...
1
by: Dunc | last post by:
I have a site with a number of pages that make use of an ID and an anchor in the querystring (e.g. www.mysite.com/news.aspx?NewsTypeID=7#NewsID_49). For some reason, when it's visited by a...
1
by: TF | last post by:
This group came through for me last time so here we go again. My page shows paint colors, brand name, product code, etc in a gridview with the background matching the paint color. Several links on...
3
by: pbd22 | last post by:
Hi. I need some help with structuring my query strings. I have a form with a search bar and some links. Each link is a search type (such as "community"). The HREF for the link's anchor looks...
10
by: sheldonlg | last post by:
I got an unusual request. One customer wants a password/access made available to a user that is valid for only, say, ten minutes. I know that I can enforce this by having a revalidation of the...
24
by: MU | last post by:
Hello I have some code that sets a dropdownlist control with a parameter from the querystring. However, when the querystring is empty, I get an error. Here is my code: Protected Sub...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.