Raised This Month: $ Target: $400
 0% 

Mysql columns in a loop


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
bowisen
New Member
Join Date: Apr 2015
Old 04-30-2015 , 05:51   Mysql columns in a loop
Reply With Quote #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 is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode