I know there is a simple answer but I can’t seem to put this together. I am successfully pulling an array from a MySQL table in the following code, but I would like to assign individual PHP variables to each item.
<?php
$con = mysql_connect("$hostname","$username","$password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$database", $con);
$result = mysql_query("SELECT * FROM table WHERE state=1");
while($row = mysql_fetch_array($result))
{
$value=$row['id'];
}
mysql_close($con);
?>
When I run this loop I get the output of the id’s as 1,2,3,4,5,6,7. How can I go about assigning individual PHP variables to each of these values?
You can put the variables in an array.
and then reference it as
$value[0],$value[1]…Also take a look at list which allows you to assign individual variables as if they were an array.