i would like to ask you if you ever have similar problems with sql.....currently programming a various search tool using 1database ( input type..... ->search working fine with all the data ) but when i use the same database for data search via 2xSelect menues ......some strange thing happens ....everything goes well until i reach a row with id22 after this number no results are shown ?!
There's not much we can say (including whether we've even seen "similar problems") without seeing at least your code (but probably your DB schema and at least some sample content as well).
sample : ($subcat is the ID of the island selected and works well until airport_id22)
$isql="SELECT airport_name,airport_code,region_name from airport,island,region WHERE airport_id=island_id AND region_id=airport_region AND airport_island='$subcat' ";
Do you actually have 3 tables named "airport", "island", and "region" as shown on "city.jpg" ...?
/!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade!/!!!\ ereg() is deprecated --- don't use it!
dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket
You need to improve the query syntax, as you're using a triple join. I'll play with it and see what I can come up with; however, there are some gurus here who can do it in their head. Perhaps one of them will drop in soon.
/!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade!/!!!\ ereg() is deprecated --- don't use it!
dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket
this is the select query which runs ok until id22 :-)
$quer2=mysql_query('SELECT region_id,region_name FROM region ORDER BY region_name ASC');
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT region_id,island_id,island_name FROM island, region WHERE region_id=island_region AND region_id=$cat ORDER BY island_name ASC ");
}else{$quer=mysql_query("SELECT island_id,island_name FROM island ORDER BY island_name ASC"); }
+ for <input type=text > this is the sql which runs perfect using same database :
$sql="SELECT airport_id, airport_name, region_name, airport_code, island_name FROM airport, region, island WHERE airport_name LIKE '%" . $name . "%' AND region_id=airport_region AND island_id=airport_island";
Is region and island completely unrelated enteties? Otherwose the join should most definitely be
Code:
FROM airport AS a
INNER JOIN region AS r ON a.region_id = r.id
INNER JOIN island AS i ON r.island_id = i.id
Assuming that one island can contain several regions. Should it be the other way around, so that a region can contain several islands, you'd instead have
Code:
FROM airport AS a
INNER JOIN island AS i ON a.island_id = i.id
INNER JOIN region AS r ON i.region_id = r.id
I'd also recommend that you change your syntax from a comma-join (FROM t1, t2, t3 WHERE) into explicitly listing the joins and their conditions like I have. Both will achieve the exact same results, so you should do whatever you prefer. In my opinion it's a lot easier to see how things are related when you use the join syntax. I also believe that there is a definit logic difference between a where condition and a join condition even though they work the same way programatically.
Bookmarks