You are here: Re: Query Problem « All PHP « IT news, forums, messages
Re: Query Problem

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)

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация