Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder olidenia's Avatar
    Join Date
    Oct 2009
    Location
    Sitting In Front Of A Screen
    Posts
    110
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Create array from sql data, question.

    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:

    PHP Code:
    $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.
    It's easy once you know how...

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,292
    Thanks
    4
    Thanked 202 Times in 199 Posts
    What have you tried? Show us what you have and we should be able to help.
    Dave .... HostMonster for all of your hosting needs

  • #3
    Regular Coder olidenia's Avatar
    Join Date
    Oct 2009
    Location
    Sitting In Front Of A Screen
    Posts
    110
    Thanks
    16
    Thanked 4 Times in 4 Posts
    It's something like this, but this is totaly wrong.

    Code:
    $users_result = mysql_query("SELECT * FROM access");
    while($row = mysql_fetch_array($users_result))
    {
    echo '$row[user]' => '$row[password]';
    }
    I want it to populate the results in here:

    Code:
    $LOGIN_INFORMATION = array( 
    HERE
    );
    It's easy once you know how...

  • #4
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Instead of echoing, insert the values into your login array, something like this:

    PHP Code:
    $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:

    PHP Code:
    print_r($LOGIN_INFORMATION); 
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • Users who have thanked Rowsdower! for this post:

    olidenia (11-17-2010)

  • #5
    Regular Coder olidenia's Avatar
    Join Date
    Oct 2009
    Location
    Sitting In Front Of A Screen
    Posts
    110
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Perfect, just learnt a very important thing.

    Works fine.

    Thanks!
    It's easy once you know how...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •