I'm trying to list the names of cities in an array on php-mysql, but when I Use these lines - & gt; ;
$ sql = "Select city from the list"; $ Sorgu = mysql_query ($ sql); While ($ rs = mysql_fetch_assoc ($ sorgu)) {print_r ($ rs); } Mysql_free_result ($ sorgu); (<0) => (London) Array ([0] => PARIS) Array ([0] => OSLO) It has 4 cities and 4 arrays but I want them Like to list Array ([0] = & gt; ISTANBUL [1] => London [2] => Paris [3] => Newer) >
What should I do?
Just add the city to another array:
$ Array = array (); While ($ rs = mysql_fetch_assoc ($ sorgu)) {$ array [] = $ rs ['city']; } Print_r ($ array); The code for your question will actually output:
array ([city] => gt; ISTANBUL) array ([city] => London) Note Array ([city] => PARIS) arrow ([city] = & gt; OSLO] city key If you select mysql_fetch_row () .
, you will only receive the output that the mysql _ * library is disliked, consider upgrading PDO or MySQLi do.
No comments:
Post a Comment