Jump to content


Photo

How to make a search with many options


  • Please log in to reply
26 replies to this topic

#21 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 28 October 2006 - 02:01 PM

Set up the joins like this

SELECT l.*, c.name, d.name
FROM listings l
INNER JOIN cities c ON l.city = c.city
INNER JOIN district d ON l.district = d.district
$whereclause

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#22 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 28 October 2006 - 04:12 PM

Thx will try later.

#23 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 28 October 2006 - 05:10 PM

Now i ahve something like:

$q = mysql_query("SELECT listings.*, cities.name, districts.name FROM listings INNER JOIN cities ON listings.city = cities.city INNER JOIN districts ON listings.district = districts.district $whereclause");

and when i try to view {$row['city']} i get the number... for example 1

#24 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 28 October 2006 - 06:11 PM

Change first bit to

$q = mysql_query("SELECT listings.*, cities.name as cityname, districts.name as distname ...

Then try viewing {$row['cityname']}
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#25 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 28 October 2006 - 06:51 PM

Yep it now works great.10x :)

#26 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 03 November 2006 - 02:41 PM

By the way its form now i get an error again:

if(!empty($district)){
	$district = join ("','", $district);
$where[] = "(district IN ('$district'))";
}

when i view the output its not in('1','2'.....)
but 1','2 ... and i get Column 'district' in where clause is ambiguous

Help please

#27 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 03 November 2006 - 04:31 PM

If you view $district you will get 1','2

If it says district is ambiguous then you must be selecting the same column name from more than one table, maybe because you are using "SELECT * FROM). Specify which one to use eg

$where[] = "(listings.district IN ('$district'))";
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users