Jump to content

[SOLVED] proper syntax...


galvin

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/154748-solved-proper-syntax/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/154748-solved-proper-syntax/#findComment-813775
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/154748-solved-proper-syntax/#findComment-813785
Share on other sites

Archived

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

×
×
  • 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.