jimmyt1988 Posted December 7, 2009 Share Posted December 7, 2009 <?php function countryList(){ $numberOfCountries = mysql_query("SELECT * FROM countrylist") or die(mysql_error()); $result = mysql_num_rows($numberOfCountries); $countryList = mysql_query("SELECT * FROM countrylist") or die(mysql_error()); $row = mysql_fetch_array( $countryList ); for ( $i = 0; $i < $result; $i++ ){ /*line 45*/echo '<option value = "' . $row[$i] . '">' . $row[$i] . '</option>'; } } ?> is returning: Notice: Undefined offset: 2 in C:\wamp\www\whichcomponent.co.uk\assets\formFunctions.php on line 45 not only that.. it actually keeps going until it has one all 239 countries. Why is this? Quote Link to comment https://forums.phpfreaks.com/topic/184324-country-list-problem/ Share on other sites More sharing options...
premiso Posted December 7, 2009 Share Posted December 7, 2009 while ($row = mysql_fetch_array( $countryList )) { foreach ($row as $value) { echo '<option value = "' . $value . '">' . $value . '</option>'; } } I highly doubt that is what you want, I think you are after something like this instead: while ($row = mysql_fetch_array( $countryList )) { echo '<option value = "' . $row[0] . '">' . $row[0] . '</option>'; } Given that your table has the country name at $row[0], you should really define the columns you want out of the table in the MySQL select statement so you know what is at which index, it will also improve your MySQL performance. Quote Link to comment https://forums.phpfreaks.com/topic/184324-country-list-problem/#findComment-973122 Share on other sites More sharing options...
jimmyt1988 Posted December 7, 2009 Author Share Posted December 7, 2009 I.... Love... you. Quote Link to comment https://forums.phpfreaks.com/topic/184324-country-list-problem/#findComment-973128 Share on other sites More sharing options...
blueman378 Posted December 7, 2009 Share Posted December 7, 2009 I.... Love... you. Run while you still can premiso... Quote Link to comment https://forums.phpfreaks.com/topic/184324-country-list-problem/#findComment-973143 Share on other sites More sharing options...
premiso Posted December 7, 2009 Share Posted December 7, 2009 You see me helping here is kind of like a male stripper working for free. At first they wonder about you, then they see your package and fall in love instantly. It is a hazard of the trade I am afraid Quote Link to comment https://forums.phpfreaks.com/topic/184324-country-list-problem/#findComment-973144 Share on other sites More sharing options...
MadTechie Posted December 8, 2009 Share Posted December 8, 2009 LOL, That's a lot of appreciation for such a small package amount of code, Quote Link to comment https://forums.phpfreaks.com/topic/184324-country-list-problem/#findComment-973145 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.