A mySQL table called 'countries' lists the countries in the world, each with an id number. This code: $sql="SELECT * FROM countries"; $array=do_sql($sql); while ($row = mysql_fetch_array($array, MYSQL_ASSOC)) { $n=$row['countryID']; $m=$row['countryName']; $carray[$n]=$m; } doesn't work that great. For example, $carray[100] contains "El" instead of "El Salvador", $carray[81] contains "Costa" instead of "Costa Rica", and all the other countries with multi-word names come back as just the first word. I've checked the db using phpMyAdmin - edited the entries manually incase the space was some weird character, but that hasn't helped. It could be the db, but the structure of the table is "countryName, varchar(30), latin1_swedish_ci". Maybe it's the php ... Can anyone shed light on why I'm getting "Trinidad" instead of "Trinidad and Tobago" etc?
edit array data structure and programming lesson $coder=count($carray); for($xxx=0;$xxx<$coder;$xxx++) : if(strlen($carray[$xxx])<strlen($carray[$xxx-1])) { $phoenix=$carray[$xxx-1]; $carray[$xxx]=$carray[$xxx-1]; $carray[$xxx-1]=$phoenix; } else { endfor; } endfor; PHP: sample algorithm you are do advanced code
Aha! Though not exactly the solution I need, it prompted me to check the contents of the array and where it sat in the html. Seems the space in the html was the problem. Thanks anyway - you helped me fix it. Note to self ... be more patient.