Thread
:
Mysql columns in a loop
View Single Post
Author
Message
bowisen
New Member
Join Date: Apr 2015
04-30-2015 , 05:51 Mysql columns in a loop
#
1
Let's say I have a Mysql table with the columns year_2012, year_2013 and year_2014. I select all columns in the table
$fraga = "SELECT * FROM TABLE WHERE medlemsnr=12 LIMIT 1";
$svar = mysqli_query($conn,$fraga);
$row = mysqli_fetch_array($svar);
extract ($row);
If I want to display the value of year_2013 it works with 'echo $year_2013'.
My problem is that I want to make a loop to display all three columns. I have tried this but it doesn't work:
for ($theYear=2012;theYear<2015;theYear++) {
echo $year_$theYear;
}
Is there a solution?
bowisen
View Public Profile
Send a private message to bowisen
Find More Posts by bowisen