Jump to content

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!

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.