View Single Post
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 04-30-2015 , 11:34   Re: Mysql columns in a loop
Reply With Quote #2

Quote:
Originally Posted by bowisen View Post
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?
Could you explain what you are trying to do with the information? What's your final goal?

Your code is PHP, and doesn't seem to be related to SourceMod scripting at all.

BTW; in the future, then post your code into [CODE] tags.
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline