making $var = $text$var

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

making $var = $text$var

Post by Jr »

I have a function that takes an 'option' box and makes whatever value is passed in the function the variable for that = 'selected'. For example:

Code: Select all

function bday_day($text)
{
  IF ($text == "")
{ $na = "selected"; }
ELSE
{
  $day$text = "selected";
}

print "<select name='bday_day'>";
  print "<option value='' $na></option>";
  print "<option value='1' $day1>1</option>";
  print "<option value='2' $day2>2</option>";
  print "<option value='3' $day3>3</option>";
  print "<option value='4' $day4>4</option>";
  print "<option value='5' $day5>5</option>";
  print "<option value='6' $day6>6</option>";
  print "<option value='7' $day7>7</option>";
  print "<option value='8' $day8>8</option>";
...so on...

I'm basically just trying to make $dayX = 'selected' but i can't make a variable $day$text = "selected"; is there a way i can get this to work (or a better way i should be doing this?

Thanks,
Jr-

Jcart | If you are going to post code of any kind, please review Posting Code in the Forumsfirst
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post by Bennettman »

Code: Select all

${day.$text} = 'selected';
You'll want to do some validation if it's user input.
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post by Jr »

Hmm... used it like this and it doesn't seem to work.

* * *

Code: Select all

IF ($text == "")
{ $na = "selected"; }
ELSE
{ ${day.$text} = "selected"; }
* * *

Don't really understand why... help?!?


Jcart | If you are going to post code of any kind, please review Posting Code in the Forumsfirst
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post by Jr »

oops... my bad... typed it in wrong (lol). Thanks for the help.

Jr-
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post by Bennettman »

No problem :wink:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

remember to quote your string literals.
Post Reply