Connecting Tech Pros Worldwide Forums | Help | Site Map

SQL statement help

Newbie
 
Join Date: Feb 2008
Posts: 28
#1: Mar 18 '08
i trying to read data from quite a few tables.. Now the statement works well except when i include the where e.equipmentLocationID = l.equipmentLocationID AND e.cabinetID = c.cabinetID AND e.equipmentOsID= osy.equipmentOsID AND e.equipmentServiceLevelID = s.equipmentServiceLevelID AND e.equipmentTypeID = eq.equipmentTypeID . But i need to include since the output i want is not the ID but the field.
I am using PHP...


Expand|Select|Wrap|Line Numbers
  1. $query = "select e.equipmentName, e.equipmentSerTagNum,l.location,c.name , osy.osName , s.type, e.hardwareDescription,e.macAddress,e.rackNum, eq.type,e.hostServerName,e.updatedDate,e.warrantyStartDate, e.warrantyEndDate ,e.equipmentBrand,e.equipmentApplication
  2.         from equipmentInfo as e, equipmentLocation as l, cabinet as c, os as osy ,serviceLevelType as s, equipmentType as eq
  3.  
  4. where e.equipmentLocationID = l.equipmentLocationID AND e.cabinetID = c.cabinetID AND e.equipmentOsID= osy.equipmentOsID AND e.equipmentServiceLevelID = s.equipmentServiceLevelID AND e.equipmentTypeID = eq.equipmentTypeID 
  5.  
  6. And e.equipmentName like \"%$trimmed%\" or  e.equipmentSerTagNum like \"%$trimmed%\"  
  7.   order by e.equipmentName"; 
  8.  
  9.  
  10.  

ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Mar 18 '08

re: SQL statement help


Do you get an error, and which one, or is the SQL statement executed without taking the WHERE clause ? Do you have a [php]or die("error ".mysql_error());[/php] to catch errors? If not surre show the PHP mysql_* command used.

Ronald
Newbie
 
Join Date: Feb 2008
Posts: 28
#3: Mar 18 '08

re: SQL statement help


Expand|Select|Wrap|Line Numbers
  1. connect();
  2.  
  3.  
  4. // Build SQL Query  
  5.  
  6. $query = "select e.equipmentName, e.equipmentSerTagNum,l.location,c.name , osy.osName , s.type, e.hardwareDescription,e.macAddress,e.rackNum, eq.type,e.hostServerName,e.updatedDate,e.warrantyStartDate, e.warrantyEndDate ,e.equipmentBrand,e.equipmentApplication
  7.         from equipmentInfo as e, equipmentLocation as l, cabinet as c, os as osy ,serviceLevelType as s, equipmentType as eq
  8.  
  9.         where e.equipmentLocationID = l.equipmentLocationID AND e.cabinetID = c.cabinetID AND e.equipmentOsID= osy.equipmentOsID AND e.equipmentServiceLevelID = s.equipmentServiceLevelID AND e.equipmentTypeID = eq.equipmentTypeID 
  10.  
  11.         AND e.equipmentName like \"%$trimmed%\" or  e.equipmentSerTagNum like \"%$trimmed%\"  
  12.   order by e.equipmentName" or die("error".mysql_error()); 
  13.  
  14.  
  15.  $numresults=mysql_query($query);
  16.  
  17.  
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#4: Mar 18 '08

re: SQL statement help


So?? see my last post. Do you get an error or is the statement just executed without anything returning?

Ronald
Newbie
 
Join Date: Feb 2008
Posts: 28
#5: Mar 18 '08

re: SQL statement help


Quote:

Originally Posted by ronverdonk

So?? see my last post. Do you get an error or is the statement just executed without anything returning?

Ronald

it executed without anything returning
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#6: Mar 18 '08

re: SQL statement help


So the statement is correct and working. To me it looks like there is no database result to be returned from that statetement.

Ronald
Newbie
 
Join Date: Feb 2008
Posts: 28
#7: Mar 18 '08

re: SQL statement help


i getting results without the following statement.
Expand|Select|Wrap|Line Numbers
  1.  where e.equipmentLocationID = l.equipmentLocationID AND e.cabinetID = c.cabinetID AND e.equipmentOsID= osy.equipmentOsID AND e.equipmentServiceLevelID = s.equipmentServiceLevelID AND e.equipmentTypeID = eq.equipmentTypeID 
  2.  
but i need to include it for the outpuit i looking for..
whenever i include it returns nothing...
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#8: Mar 18 '08

re: SQL statement help


Then NOTHING matches that where clause. The combination of these restrictions is not there.

When you are pertinent that there must be a result, then do some debugging.

Have you tried to issue the WHERE clause with fewer restrictions? Like starting with the first one and see what is returned. If anything is returned, gradually expand the where clause until it returns nothing?

Ronald
Reply


Similar MySQL Database bytes