Jump to content

Recommended Posts

<?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?

Link to comment
https://forums.phpfreaks.com/topic/184324-country-list-problem/
Share on other sites

       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.

Link to comment
https://forums.phpfreaks.com/topic/184324-country-list-problem/#findComment-973122
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.