SQL statement help | Newbie | | Join Date: Feb 2008
Posts: 28
| |
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... -
$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
-
from equipmentInfo as e, equipmentLocation as l, cabinet as c, os as osy ,serviceLevelType as s, equipmentType as eq
-
-
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
-
-
And e.equipmentName like \"%$trimmed%\" or e.equipmentSerTagNum like \"%$trimmed%\"
-
order by e.equipmentName";
-
-
-
|  | Moderator | | Join Date: Jul 2006 Location: The Netherlands
Posts: 4,139
| | | 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
| | | re: SQL statement help -
connect();
-
-
-
// Build SQL Query
-
-
$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
-
from equipmentInfo as e, equipmentLocation as l, cabinet as c, os as osy ,serviceLevelType as s, equipmentType as eq
-
-
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
-
-
AND e.equipmentName like \"%$trimmed%\" or e.equipmentSerTagNum like \"%$trimmed%\"
-
order by e.equipmentName" or die("error".mysql_error());
-
-
-
$numresults=mysql_query($query);
-
-
|  | Moderator | | Join Date: Jul 2006 Location: The Netherlands
Posts: 4,139
| | | 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
| | | 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
|  | Moderator | | Join Date: Jul 2006 Location: The Netherlands
Posts: 4,139
| | | 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
| | | re: SQL statement help
i getting results without the following statement. -
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 it for the outpuit i looking for..
whenever i include it returns nothing...
|  | Moderator | | Join Date: Jul 2006 Location: The Netherlands
Posts: 4,139
| | | 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
|  | Similar MySQL Database bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,467 network members.
|