0

Lets say I have a mysql database called "pcode" with only one table, called "uk_postcodes" and I want to populate my array with only the first column, called "postcodes". What is missing from the following code:

    //link to mysql server
    $link = mysql_connect('localhost', 'root', 'root');
    mysql_select_db('pcode'); 

    $sql = "SELECT * FROM `ukpostcodes`";
    $query = mysql_query($sql);

$var = array();
1
  • usual way to get the data from database is missing, which you used to use 1000 times already, but forgot here for whatever reason. Commented Jan 26, 2011 at 12:41

1 Answer 1

7
$sql = "SELECT postcodes FROM ukpostcodes";
$result = mysql_query($sql);

$var = array();
while ($row = mysql_fetch_array($result)) {
  $var[] = $row['postcodes'];
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.