Jump to content

Archived

This topic is now archived and is closed to further replies.

WinnieThePujols

Let's See... Auto-Incrementing Variable + SQL Info..

Recommended Posts

Alright, I'll try and explain this as best I can.

 

I have baseball player's contracts listed in a big database. The years of their contract are listed in under columns entitled "contract_byr1," "contract_byr2," (etc) all the way up to "contract_byr10." Also, there's another column called "contract_length."

 

Now, I call to the SQL database using...

$conRow = mysql_fetch_array($getContract);
$totalYears = $conRow['contract_years'];

 

Now, once it comes time to display the salary, I have a for loop set up like this:

for($displayYear = '1'; $displayYear <= $totalYears; $currentYear++)

 

OK, I tried using this code within the aforementioned loop:

print "Year $displayYear salary: " 
$curConYear = "contract_byr$currentYear";
$tempSalary = $conRow['$curConYear'];
print $tempSalary;

 

Unfortunately, it doesn't return any value... so clearly something in the above code listing is wrong! I'm 99% sure the "$conRow['$curConYear']" method doesn't work, so what alternatives do I have?

 

When it outputs, it basically looks like this:

Year 1: (nothing)

Year 2: (nothing)

etc...

 

Thanks, your support is much appreciated!

Share this post


Link to post
Share on other sites

Echo each query after constructing it. At least then you'll know exactly what the query is that isn't giving you what you want. Maybe that'll point the way.

Share this post


Link to post
Share on other sites

I found out what I was doing wrong.

 

I had it like this:

print $conRow['$tempVal'];

 

But I guess with the half quotes around $tempVal it was using the name of the variable, as opposed to the value of it! Doh!

 

Thanks people.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.