Unusual Query Help Request

This is a discussion on Unusual Query Help Request within the MySQL Database forums, part of the Database Forums category; I have a query where I'm attempting to pull data from 3 different tables using php and mysql. I ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-09-2007
cov
 
Posts: n/a
Default Unusual Query Help Request

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
Reply With Quote
  #2 (permalink)  
Old 11-09-2007
Jerry Stuckle
 
Posts: n/a
Default Re: Unusual Query Help Request

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.
jstucklex@attglobal.net
==================

Reply With Quote
  #3 (permalink)  
Old 11-10-2007
cov
 
Posts: n/a
Default Re: Unusual Query Help Request

On Fri, 09 Nov 2007 16:31:09 -0500, Jerry Stuckle
<jstucklex@attglobal.net> wrote:

>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
Reply With Quote
  #4 (permalink)  
Old 11-10-2007
Michael Austin
 
Posts: n/a
Default Re: Unusual Query Help Request

cov wrote:
> On Fri, 09 Nov 2007 16:31:09 -0500, Jerry Stuckle
> <jstucklex@attglobal.net> wrote:
>
>> 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> )
Reply With Quote
  #5 (permalink)  
Old 11-10-2007
cov
 
Posts: n/a
Default Re: Unusual Query Help Request

On Fri, 09 Nov 2007 22:20:38 -0600, Michael Austin
<notknown@thistime.inf> wrote:


>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'
Reply With Quote
  #6 (permalink)  
Old 11-10-2007
Jerry Stuckle
 
Posts: n/a
Default Re: Unusual Query Help Request

cov wrote:
> On Fri, 09 Nov 2007 16:31:09 -0500, Jerry Stuckle
> <jstucklex@attglobal.net> wrote:
>
>> 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.
jstucklex@attglobal.net
==================

Reply With Quote
  #7 (permalink)  
Old 11-10-2007
Jerry Stuckle
 
Posts: n/a
Default Re: Unusual Query Help Request

cov wrote:
> On Fri, 09 Nov 2007 22:20:38 -0600, Michael Austin
> <notknown@thistime.inf> wrote:
>
>
>> 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.
jstucklex@attglobal.net
==================

Reply With Quote
  #8 (permalink)  
Old 11-10-2007
cov
 
Posts: n/a
Default Re: Unusual Query Help Request

On Sat, 10 Nov 2007 00:01:21 -0500, Jerry Stuckle
<jstucklex@attglobal.net> wrote:

>cov wrote:
>> On Fri, 09 Nov 2007 16:31:09 -0500, Jerry Stuckle
>> <jstucklex@attglobal.net> wrote:
>>
>>> 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?
Reply With Quote
  #9 (permalink)  
Old 11-10-2007
Rik Wasmus
 
Posts: n/a
Default Re: Unusual Query Help Request

On Sat, 10 Nov 2007 07:43:13 +0100, cov <coverlandNS914@yahoo.com> wrote:

> On Sat, 10 Nov 2007 00:01:21 -0500, Jerry Stuckle
> <jstucklex@attglobal.net> wrote:
>
>> cov wrote:
>>> On Fri, 09 Nov 2007 16:31:09 -0500, Jerry Stuckle
>>> <jstucklex@attglobal.net> wrote:
>>>
>>>> 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
Reply With Quote
  #10 (permalink)  
Old 11-10-2007
cov
 
Posts: n/a
Default Re: Unusual Query Help Request

On Sat, 10 Nov 2007 18:13:17 +0100, "Rik Wasmus"
<luiheidsgoeroe@hotmail.com> wrote:


>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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:07 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0