| 
	
 | 
 Posted by Lόpher Cypher on 01/02/06 08:18 
cover wrote: 
> So why is it that the following code returns data from a single table 
> just fine?  When 'all' is selected, all records are returned or if 
> another selection is selected, only the ones specific to that group 
> are returned for a single table.  Code follows. 
>  
> $query =  
>        "SELECT * 
>         FROM $table 
> 	WHERE 1 = 1 "; 
> 	if($area != "All") $query .= "and area = '".$area."'"; 
> $result = mysql_query($query); 
>  
>  
> ------------------------------------------------------------------------------------------------------------ 
> but where two tables have been successfully joined from a single form 
> and data from the form is going into 2 separate tables I run into 
> trouble on the query.   The 'all' still returns everything as it 
> should, pulling data from the two tables but individual selections 
> used in a query form drop down that includes 'all'  (i.e. to narrow to 
> more specific areas), will not work any longer?   
>  
> $query =  
>        "SELECT shakers.area, shakers.equipname, shakers.equipno, 
> shakers.coupler, motors.mccloc, motors.hp, motors.frame, motors.amps, 
> motors.rpm, shakers.notes       
>         FROM shakers, motors 
>        WHERE shakers.equipno = motors.equipno "; 
>        if($area != "All") $query .= "and area = '".$area."'"; 
> $result = mysql_query($query); 
>  
> thanks again for any replies... 
>  
 
I think the problem might be that area is an ambiguous name in this  
query (it is in both tables). Try changing it to 
if ($area != "All") $query .= "and (shakers.area='$area' or  
motors.area='$area')"; 
 
 
 
--  
 
- lΓΌpher 
--------------------------------------------- 
"Man sieht nur das, was man weiΓ" (Goethe)
 
[Back to original message] 
 |