I want to be able to store (not echo) some data that has been selected from a mysql database in a php array. So far, I have only been able to echo the information, I just want to be able to store it in an array for later use. Here is my code:
$query = "SELECT interests FROM signup WHERE username = '$username'";
$result = mysql_query($query) or die ("no query");
while($row = mysql_fetch_array($result))
{
echo $row['interests'];
echo "<br />";
}
You could use
This will basically store all of the data to the
$result_arrayarray.I’ve used
mysql_fetch_assocrather thanmysql_fetch_arrayso that the values are mapped to their keys.I’ve also included
mysql_real_escape_stringfor protection.