I have a feeling I’m going to get scolded for this but here is the question.
$seq_numbers = range('1', '24');
foreach($seq_numbers as $seq_number)
{
Bullet <?php echo $seq_number;?>
// (this successfully creates - Bullet 1, Bullet 2, etc. -
below is the problem.
<?php echo $db_rs['bullet_($seqnumber)'];?>
} // this one doesn't work.
I’ve tried
with curly brackets {}
I basically have a few columns that are named same except for number at the end (bullet_1, bullet_2, bullet_3, etc.) and want to get the results using a loop.
Your problem is, that PHP doesn’t replace variables inside strings enclosed with single quotes. You need to use
$db_rs["bullet_{$seq_number}"]or one of those:Even shorter, but a little less clear:
An entirely different approach would be to loop over the result array. Then you don’t even need
$seq_numbers. Just as an afterthought.Oh…and watch out for how you spell your variables. You are using
$seq_numberand$seqnumber.