Using variables as a column name
Posted: Tue Dec 05, 2006 7:53 pm
HI there.
I am new to PHP and am having a problem. I have several column names in mySql that are named "page1", "page2", "page3", etc up to "page20". When I do an if statement, instead of calling it 20 times for each column name, is there any way to loop it so it works something like this:
With the intention that "echo '$page'.$counter;" will display the contents of that field. When ever I try something like the above I get $page1 or $page2, etc.
Thanks for your help.
I am new to PHP and am having a problem. I have several column names in mySql that are named "page1", "page2", "page3", etc up to "page20". When I do an if statement, instead of calling it 20 times for each column name, is there any way to loop it so it works something like this:
Code: Select all
for ( $counter = 1; $counter <= 20; $counter ++) {
echo '$page'.$counter;
echo "<br>";
}Thanks for your help.