Jump to content


Photo

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


  • Please log in to reply
2 replies to this topic

#1 WinnieThePujols

WinnieThePujols
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 12 January 2006 - 07:08 AM

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!

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 12 January 2006 - 07:12 AM

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.
Legend has it that reading the manual never killed anyone.
My site

#3 WinnieThePujols

WinnieThePujols
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 12 January 2006 - 07:22 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users