while ($row = mysql_fetch_array($result)) {
$button1 = $row['button1'];
$button2 = $row['button2'];
$button3 = $row['button3'];
$button4 = $row['button4'];
$button5 = $row['button5'];
$button6 = $row['button6'];
$button7 = $row['button7'];
$button8 = $row['button8'];
$button9 = $row['button9'];
$button10 = $row['button10'];
$button11 = $row['button11'];
$button12 = $row['button12'];
$button13 = $row['button13'];
$button14 = $row['button14'];
}
thanks.!
How would I simplify this little code????
Moderator: General Moderators
-
flashlevel
- Forum Newbie
- Posts: 1
- Joined: Wed May 01, 2002 11:47 am
-
johndoe110479
- Forum Newbie
- Posts: 1
- Joined: Wed May 01, 2002 12:44 pm
- Location: Bucharest, Romania
- Contact:
Try this:
Code: Select all
<?
$variable_start="button";
while ($row = mysql_fetch_array($result))
{
for($i=1; $i<=14; $i++)
{
$variable_name=$variable_start.$i;
$$variable_name=$rowї$variable_name];
}
}
?>A more generic code which will work with just about anything.
The $count function allows for unlimited number of buttons without having to recode the for loop eac htime you add a button.
Code: Select all
<?
$sql = mysql_query("SELECT * FROM tbl_name");
$rows = mysql_fetch_array($sql);
$variable_start="button";
$count = count($rows)
for($i=1; $i<=$count; $i++)
{
$variable_name=$variable_start.$i;
$$variable_name=$rowї$variable_name];
}
?>- sam
- Forum Contributor
- Posts: 217
- Joined: Thu Apr 18, 2002 11:11 pm
- Location: Northern California
- Contact:
Simplify it a little more and make it WORK
Cheers Sam 
Code: Select all
$i=0;
# Using a loop at this point will not work as you want it to.
# Every iteration of the loop you will lose the last row's data
$row = mysql_fetch_array($result);
$keys = array_keys($row);
foreach($keys as $key){
$$key = $rowї$key];
}