galvin Posted April 19, 2009 Share Posted April 19, 2009 I am doing a mysql query that starts... SELECT week{$_SESSION['week']}opp FROM opponents .... That runs fine. Then I create an array for the results of that query called $results and I do the following... if ($results['week{$_SESSION['week']}opp'] == 'whatever') { other code here } But it keeps giving me errors like... Parse error: syntax error, unexpected T_STRING, expecting ']' in C:\wamp\www\mysite\index.php on line 525 I can't figure out how to put apostrophes (or the "{" symbols, or maybe parentheses?) to get it to accept that if statement's syntax. Any ideas? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 19, 2009 Share Posted April 19, 2009 You could always give the column in the result an alias and use that: SELECT week{$_SESSION['week']}opp AS week FROM opponents if ($results['week'] == 'whatever') { //other code here } That said, i've got a feeling you're going about this in a particularly bad way. Do you have an awful lot of columns in the table like week1opponent, week2opponent, ..., weeknoppponent? You should probably take a look at database normalization. This tutorial might be a good place to start. Quote Link to comment Share on other sites More sharing options...
galvin Posted April 19, 2009 Author Share Posted April 19, 2009 Thanks, using an alias will work. And yes, I do have many columns It's an NFL schedule and there are 32 teams and I list out each week's opponent for all 32 teams. So for each of the 32 teams, there is a week1opp, week2opp, week3opp, thru week17opp. I don't know how to do it any "cleaner" but I'll definitely check out the tutorial you referenced. Thanks a lot. Quote Link to comment 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.