Jump to content

MYSQL PHP Select question


boko605

Recommended Posts

Hi, i have some troubles with a script.

I have 2 DB.

DB1 - in witch i collect information about propeties(real estates).

DB2 - in witch i have the names of the cities in cyrilic and in latin.

My web site have two version. Bulgarian and English.

When someone make a search by city, each city has a number that is the same as the ID in DB2.

 

$query = "select d1.* , db2.citynameinenglish // must select all the info from DB1 and the name of the city in english

              from DB1 d1, DB2 d2

where d1.salerent='$salerent'"; // sale or for rent

if($type!="")  $query=$query." and d1.type='$type'"; // if the type of the property is selected

if($city!="")   $query=$query." and d2.city='$city'"; // if a city is selected

if($price!="") $query=$query."  and d1.price<='$price"; // if a price is inputed

 

$result = mysql_query($query);

$num_results = mysql_num_rows($result);

 

Ok, in my opinion this must work but it doesnt. I have 10 entries in DB1 and the result of this query is more than 400 entries?? ???

Any suggestions?

Link to comment
Share on other sites

I'm not certain what you're trying to select - a list of city names?

 

I would guess that the problem is the d1.*

 

Perhaps it's multiplying all d1 rows by number of db2.citynameinenglish

 

Does that sound possible?

 

Also, you refer to one db as d1 (as you've named it) and the other as db2. (as though you haven't named it). Maybe try d2. instead?

 

Link to comment
Share on other sites

Assuming that DB1 and DB2 are not actually databases and refer to tables, I do not see any SQL that joins DB1 and DB2, something like:

 

SELECT d1.*, d2.citynameinenglish
FROM DB1 d1, DB2 d2
WHERE d1.cityid = d2.cityid

OR

SELECT d1.*, d2.citynameinenglish
FROM DB1 d1
     INNER JOIN DB2 d2 ON d1.cityid = d2.cityid

 

FYI: db2 should be d2 in the SELECT clause of your query, boko605.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.