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
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
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
Share on other sites

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.