Jump to content

using array to store a while loop.


dhope

Recommended Posts

Hi,

 

Is it possible to use an array to store a while loop? I am trying to retrieve some information from my database to store in an array.

 

I am trying to store about five of my customer id's, I thought this way was possible and that I had done it before. unfortunately I am getting the following error "Fatal error: [] operator not supported for strings" if possible please can someone point me in the right direction. Is there an easy for me to store all of the ids that come from the database?

 

My code so far...

 

$result = mysql_query("SELECT * FROM customers WHERE $search_field = \"$search_term\"")

or die(mysql_error()); 

 

 

while($row = mysql_fetch_array( $result )) {

 

 

$customer_id[] =  $row['id'];

 

 

}

 

Thank you

:D

Link to comment
https://forums.phpfreaks.com/topic/238723-using-array-to-store-a-while-loop/
Share on other sites

Hi, thank you for the help :) What would be the best way of doing this that wouldn't lead to being hacked?

 

 

If you're not doing so already, you should use the mysql_real_escape_string() on $search_term before querying the database. For more information, visit http://php.net/manual/en/function.mysql-real-escape-string.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.