RE: [PHP] function sql question
return 1; return $city_id; return $cityname; You can't return 3 values...try returning an array, instead. $ret[0] = $city_id; $ret[1] = $cityname; return $ret; or... $ret[City_ID] = $city_id; $ret[CityName] = $cityname; return $ret; ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] function sql question
duh ! yeah that makes sense ! but it doesn't work ! I've no idea why but it refuses to give any information back ! I've managed to get round this by now no loger declaring it a function but just actually requiring it where i need it require (get_city_1.inc); print_r(array_values ($city)); I've also chopped the return part and just return the values $city[0] = $city_id; $city_name[1] = $city_name; Strange return 1; return $city_id; return $cityname; You can't return 3 values...try returning an array, instead. $ret[0] = $city_id; $ret[1] = $cityname; return $ret; or... $ret[City_ID] = $city_id; $ret[CityName] = $cityname; return $ret; ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] function sql question
It will work; you're just doing something wrong. Do you want to fix it, or keep doing it this way? ---John Holmes... -Original Message- From: John Fishworld [mailto:[EMAIL PROTECTED]] Sent: Sunday, May 05, 2002 10:55 AM To: [EMAIL PROTECTED]; 'PHP-General' Subject: Re: [PHP] function sql question duh ! yeah that makes sense ! but it doesn't work ! I've no idea why but it refuses to give any information back ! I've managed to get round this by now no loger declaring it a function but just actually requiring it where i need it require (get_city_1.inc); print_r(array_values ($city)); I've also chopped the return part and just return the values $city[0] = $city_id; $city_name[1] = $city_name; Strange return 1; return $city_id; return $cityname; You can't return 3 values...try returning an array, instead. $ret[0] = $city_id; $ret[1] = $cityname; return $ret; or... $ret[City_ID] = $city_id; $ret[CityName] = $cityname; return $ret; ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] function sql question
At 6:34 PM +0200 5/5/02, John Fishworld wrote: John, 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 KR 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 t_city.name 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 ...R. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php