1
$bilgi= mysql_query("SELECT age,wname,slid,sex FROM user AND city WHERE user.ci_name=(SELECT ci_id FROM city WHERE ci_name='$ciname')");
while($sutun= mysql_fetch_array($bilgi))

This is my statement of query. This gives me error and the error is supplied argument is not valid MySQL result in resource in ....

Now let me explain what I am doing. I am sending some city name to my database in order to find the unique number of the city. I send Istanbul and it's id is 2 in my database. I have 2 tables, 1 is city the other one is user. User table has age,wname,sex,slid; and ci_name part that is foreign key with the city_id. city_id is the primary key of the city table. I want to find the age, wname, slid and sex of Istanbul.

Can anyone help me how can I get throw with this error and find what I want :)?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Danny Togaer
  • 349
  • 3
  • 14
  • 2
    See http://stackoverflow.com/questions/6198104/reference-what-is-a-perfect-code-sample-using-the-mysql-extension for how to debug mySQL queries – Pekka Aug 08 '11 at 15:58

2 Answers2

4
$bilgi= mysql_query("SELECT age,wname,slid,sex FROM user, city WHERE user.ci_name=(SELECT ci_id FROM city WHERE ci_name='$ciname')");
    while($sutun= mysql_fetch_array($bilgi))

You had an AND in your FROM section, which isn't valid.

diagonalbatman
  • 17,340
  • 3
  • 31
  • 31
  • Actually looking again - i think you have your SQL wrong anyway, you only need 'user, city' if you are returning any fields from the CITY table. – diagonalbatman Aug 08 '11 at 16:00
0

You can use one Query instead of using two like you:

$query = 'SELECT age,wname,slid,sex FROM user, city WHERE user.ci_name = city.ci_id AND city.name = '".$yourCityNameYouSeek."'';

The only thing I don't get is which table-column your city name is stored. In user-table you have ci_name (is that a NAME or an ID)?

diagonalbatman
  • 17,340
  • 3
  • 31
  • 31
scube
  • 1,931
  • 15
  • 21