Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2010
    Thanked 0 Times in 0 Posts

    Am I going crazy or is there something else wrong?

    I have this:

    $qry_city = "select * from " . CITY . " where `country_id`='$row_country[id]' order by `city_name` ASC";
    $rs_city = mysql_query($qry_city);
    which should order the city names in alphabetical order, right? It's not, it's listing them in date added order.

    Just checking there is nothing wrong with the above code first before I start pulling apart every other piece of the page!
    I've been making animations for my daughter. Tell me what you think!

    Pickles and the Bully
    Where are you Pickles!?!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,379 Times in 4,344 Posts
    How can we tell, without seeing your schema and some sample data?

    But offhand I see two things about that query that worry me:
    (1) You are specifying the name of the TABLE by means of ... what?
    CITY isn't a PHP variable, so what is it?
    And in any case, why is it dynamically specified? PLEASE don't tell us you have more than one table of ctiy_name's.

    (2) You are limiting the selection to one country, good. You are using a country *apparently* obtained in another query. Probably bad. Probably you should be using *ONE* combined query, not two separate ones.


    In any case: DEBUG DEBUG DEBUG!!!!

    $qry_city = "select * from " . CITY . " where `country_id`='$row_country[id]' order by `city_name` ASC";
    echo "DEBUG SQL: " . $qry_city . "<hr/>\n";
    Look at the DEBUG output. Copy/paste the query, as you see it in the DEBUG output, to your favorite MySQL tool (phpmyadmin, or whatever you use). Execute it in the tool. Do you still see the same strange results?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts