furn355 Posted July 2, 2013 Share Posted July 2, 2013 $mailList = array ( 'name1' => 'name1@googlemail.com', 'name 2' => 'name2@tld.com', ); Is what i'm trying to do, but i want to populate it from my DB. I have tried this: $list = mysql_query("SELECT name, email FROM ".$_POST['db1'].""); $mailList = array(); while($data = mysql_fetch_array($list)) { $mailList[$list['name']] =$list['email']; } echo '<br /> var dump <br />'; var_dump($mailList); echo '<br /> var dump <br />'; but it just returns : array(1) { [""]=> NULL } Any help would be greatly appreciated Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted July 2, 2013 Share Posted July 2, 2013 $data holds the query row in your loop not $list $list = mysql_query("SELECT name, email FROM ".mysql_real_escape_string($_POST['db1'])); $mailList = array(); while($data = mysql_fetch_assoc($list)) { // probably better to use email as the array key as it is unique $mailList[$data['email']] = $data['name']; } echo '<br /> var dump <br />'; var_dump($mailList); echo '<br /> var dump <br />'; Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 2, 2013 Share Posted July 2, 2013 Always do error checking. Your query statement is flawed. If you had checked your query results and displayed MySQL_error you would have caught the error before trying to process an non-existent result. (In case you didn't notice that Neil corrected your query.) Quote Link to comment 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.