WinnieThePujols Posted January 12, 2006 Share Posted January 12, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/3180-lets-see-auto-incrementing-variable-sql-info/ Share on other sites More sharing options...
AndyB Posted January 12, 2006 Share Posted January 12, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/3180-lets-see-auto-incrementing-variable-sql-info/#findComment-10822 Share on other sites More sharing options...
WinnieThePujols Posted January 12, 2006 Author Share Posted January 12, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/3180-lets-see-auto-incrementing-variable-sql-info/#findComment-10823 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.