At 6:34 PM +0200 5/5/02, John Fishworld wrote:


Your mysql_db_query should contain either "DBWEB" (with
quotes) or $DBWEB (a var). Just DBWEB is an error.
Also, from the manual re: mysql_db_query
  Note:  This function has been deprecated since PHP 4.0.6.
  Do not use this function.
  Use mysql_select_db()  and mysql_query() instead.

Your SQL query is incorrect. The strings you use to identify
a column contain "_" instead of ".". Perhaps just an artifact
of your mailer, but the query as it is should be throwing
"unknown column t_city_name" errors. Try adding some "as"
clauses into your query to name these "virtual" columns.
Or replace the "_" with ".".

Hey, and it's nice to see a normalized database for a change :)

Your coding formatting style is likely to cause you problems.
You have (partially) indented the code the way you want to
behave logically, but your braces are all over the shop.

Try adopting one of the coding styles commonly in use and
that will almost certainly make your life easier. I use the
K&R "one true brace style" because I'm a C hacker from way
back, but you might like an extra line break before a "{".

As for this function, the first time through the loop,
unless the cityname is not "" you return 0. Since you test for
a blank cityname, I assume that's a possible return value from
the database. In this case you shouldn't return 0 then, but
instead loop though to the next result in the result set.

Try this:

function check_city_from_plz($str) {
// connect and select database
$city_query = "select distinct AS t_city_name,
t_city.id_city AS t_city_id_city from
t_city,t_zipcodecity where
(t_city_id_city = t_zipcodecity_id_city) and
(t_zipcodecity.zipcode like '$str')";

$city_result = mysql_db_query(DBWEB, $city_query);

if ($city_result) {
    while ($q = mysql_fetch_array($city_result)) {
        $city_id = $q["t_city_id_city"];
        $cityname = $q["t_city_name"];
        if ($cityname != "") {
            r["city_id"] = $city_id;
            r["cityname"] = $cityname;
            return $r;
        } // close if
    } // close while
    // return 0 if no matches after iterating through data
    return 0;
} //  close function


PHP General Mailing List (
To unsubscribe, visit:

Reply via email to