Hey guys,
I have a bit of a problem.
I'd like to assign variables to equal the result of an sql query, returned in an array. for example, each time through the loop a new variable is created $variable(number 1 - 12) = the element in the returned array from the sql query.
Here's my code.
$sql = "SELECT button_text FROM ".$table." ORDER BY buttonID";
$users = mysql_query($sql);
$i = 0;
while ($user = mysql_fetch_array($users)) {
$variable(number 1 - 12) = $user["button_text"]; <--- I want to set new var here.
$i++;
}
Any thoughts or help would be appreciated.
TIA.
setting variables in a while loop
Moderator: General Moderators
i agree with mark. why not just use an array?
Code: Select all
mysql_select_db($db);
$sql = "SELECT button_text FROM ".$table." ORDER BY buttonID";
$users = mysql_query($sql);
$buttons = array();
while ($user = mysql_fetch_array($users))
{
$buttons[] = $user['button_text'];
}