SQL statement help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • princelindie
    New Member
    • Feb 2008
    • 28

    SQL statement help

    i trying to read data from quite a few tables.. Now the statement works well except when i include the where e.equipmentLoca tionID = l.equipmentLoca tionID AND e.cabinetID = c.cabinetID AND e.equipmentOsID = osy.equipmentOs ID AND e.equipmentServ iceLevelID = s.equipmentServ iceLevelID AND e.equipmentType ID = eq.equipmentTyp eID . But i need to include since the output i want is not the ID but the field.
    I am using PHP...


    Code:
    $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";
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    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

    Comment

    • princelindie
      New Member
      • Feb 2008
      • 28

      #3
      Code:
      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);

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

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

        Ronald

        Comment

        • princelindie
          New Member
          • Feb 2008
          • 28

          #5
          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

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

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

            Ronald

            Comment

            • princelindie
              New Member
              • Feb 2008
              • 28

              #7
              i getting results without the following statement.
              Code:
               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...

              Comment

              • ronverdonk
                Recognized Expert Specialist
                • Jul 2006
                • 4259

                #8
                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

                Comment

                Working...