Forum Moderators: coopster
Is there a way i can do something like $var0 = array element[0], $var1 = array element[1], etc?
$query = "SELECT price FROM pans";
$result = mysql_query($query,$connection)
or die ("problem");
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach($line as $col_value) {
echo "<p>$col_value</p>";
}
}
Afterward you'd have $prices[0], $prices[1], $prices[2]...
If you have an aversion to arrays, you can put the values into scalar variables (like $var0) by using a php feature called variable variables [us.php.net].
$num = 0;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$variablename = 'var' . $num;
$$variablename = $line['prices'];
$num++;
}
Afterward, you'd have five variables with names as you described: $var0, $var1, $var2...