...

View Full Version : Create array from sql data, question.



olidenia
11-17-2010, 12:58 PM
Hello to all,

I have this script it's part of a login system and it puts the values USER & PASSWORD in array for further authentication:


$LOGIN_INFORMATION = array(
'User1' => '123456',
'User2' => '789101'
);

I want to populate this array from a sql table named access that has username and password databases.

how can I do this? I think i know a way of doing it but I have a problem with the hiding the last comma in the array.

djm0219
11-17-2010, 01:43 PM
What have you tried? Show us what you have and we should be able to help.

olidenia
11-17-2010, 04:38 PM
It's something like this, but this is totaly wrong.


$users_result = mysql_query("SELECT * FROM access");
while($row = mysql_fetch_array($users_result))
{
echo '$row' => '$row[password]';
}

I want it to populate the results in here:


$LOGIN_INFORMATION = array(
[U]HERE
);

Rowsdower!
11-17-2010, 04:50 PM
Instead of echoing, insert the values into your login array, something like this:


$LOGIN_INFORMATION=array();
$users_result = mysql_query("SELECT * FROM access");
while($row = mysql_fetch_array($users_result)){
$LOGIN_INFORMATION[$row['user']]=$row['password'];
}

Then, for debugging purposes, you can view what is in your login array like so:


print_r($LOGIN_INFORMATION);

olidenia
11-17-2010, 05:04 PM
Perfect, just learnt a very important thing.

Works fine.

Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum