I have this array below.

$LOGIN_INFORMATION = array(
  'user1' => 'user1password',
  'user2' => 'user2password'
);

And I want to make the array so that it loads all the username and passwords from a datbase instead. How could I do that? Any help is appreciated.

Perform a query. As you loop through the return append each return record to the array. That should be all it takes.

Although, from a design standpoint, I'm not too sure this is a good idea. It has the potential to be a HUGE security risk. If a malicious user successfully inserts the proper PHP commands into your login form, they suddenly have access to every username in your database and their associated passwords.

Yeah I was trying to do that accept I am not sure on the actual syntax for it.

Perform a query. As you loop through the return append each return record to the array. That should be all it takes.

Although, from a design standpoint, I'm not too sure this is a good idea. It has the potential to be a HUGE security risk. If a malicious user successfully inserts the proper PHP commands into your login form, they suddenly have access to every username in your database and their associated passwords.

This is how I did it on a site that I built a while ago:

while ($skill = @mysqli_fetch_assoc($lookup))
  {
  $captures[$skill['eliteId']] = $skill['eliteName'];

  // END ARRAY BUILD WHILE LOOP
  }

This dynamically generates an array similar to
$captures[1] = "Name 1"
$captures[2] = "Name 2"
$captures[3] = "Name 3"
$captures[5] = "Name 5"
$captures[7] = "Name 7"

It seems to work really well...

Thanks that worked for me I modified it a little bit, and worked great. thanks a lot.

This is how I did it on a site that I built a while ago:

while ($skill = @mysqli_fetch_assoc($lookup))
  {
  $captures[$skill['eliteId']] = $skill['eliteName'];

  // END ARRAY BUILD WHILE LOOP
  }

This dynamically generates an array similar to
$captures[1] = "Name 1"
$captures[2] = "Name 2"
$captures[3] = "Name 3"
$captures[5] = "Name 5"
$captures[7] = "Name 7"

It seems to work really well...

Member Avatar for rajarajan2017
Instead of this
$captures[$skill['eliteId']] = $skill['eliteName'];
you can also use:
array_push($captures, $skill['eliteName']);
Instead of this
$captures[$skill['eliteId']] = $skill['eliteName'];
you can also use:
array_push($captures, $skill['eliteName']);

I was not aware of that function, I'll keep it in mind in the future. Based on my research though that does not set up the array elements the way I need them set up. This creates consecutively numbered elements that contain $skill as values.

The problem is, if you look at the example, the elements' indexes are not consecutive, they are in numeric order, but they are not consecutively numbered. A very specific ID needs to be associated with each element. They need to be this way because of the way in which the data in the array is selected, generated, and used.

I suspect that the OP has a similar situation.

Member Avatar for rajarajan2017

Thats Right! I am not looked into that non-consecutive. Thanks. As you said you not aware of that function. Let trigger you that is also an array function we can used to push the elements as a consecutive one. COOL!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.