• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 130
  • Last Modified:

Displaying a region based on a url parameter

Hi all,
I want to display certain text boxes based on whether or not a url variable is equal to Yes or No. I'm doing something wrong with it just not sure what :) Here's what I have so far. I tried single quotes around the Yes but no luck there.
<?php if ($_GET['cable_y_n']) == "Yes") {
  <p>
      <label>Cable?
      <input type="text" name="textfield3" />
      </label>
  </p>
    <p>
      <label>Cable Name:
      <input name="textfield4" type="text" value="<?php echo $row_RsCables['cab_cable_name']; ?>" />
      </label>
  </p>
    <p>
      <label>Cable Description:
      <textarea name="textarea" cols="35" rows="4"><?php echo $row_RsCables['cab_desc']; ?></textarea>
      </label>
  </p>
    <?php }
0
dereksheahan
Asked:
dereksheahan
  • 3
  • 2
2 Solutions
 
Jason C. LevineNo oneCommented:
Oh, so close...

<?php if ($_GET['cable_y_n']) == "Yes") { ?>
  <p>
      <label>Cable?
      <input type="text" name="textfield3" />
      </label>
  </p>
    <p>
      <label>Cable Name:
      <input name="textfield4" type="text" value="<?php echo $row_RsCables['cab_cable_name']; ?>" />
      </label>
  </p>
    <p>
      <label>Cable Description:
      <textarea name="textarea" cols="35" rows="4"><?php echo $row_RsCables['cab_desc']; ?></textarea>
      </label>
  </p>
    <?php } ?>

Just needed to close the PHP statements at the top and bottom.  Now if the condition is true, it evaluates the stuff between the curly braces.  If not, nothing happens.
0
 
radnorCommented:
Dont we need to balance the parens???

ORIG CODE: <?php if ($_GET['cable_y_n']) == "Yes") { ?>

<?php if (($_GET['cable_y_n']) == "Yes") { ?>
----------^
0
 
Jason C. LevineNo oneCommented:
Whoops, missed that.  Good catch, radnor.

It would actually be:

<?php if ($_GET['cable_y_n'] == "Yes") { ?>

No need for double parens...
0
 
Jason C. LevineNo oneCommented:
For that matter, I don't think you need the parens at all if it is one condition.  Putting the condition in parens is just good practice for when you have a two or more tailed test...
0
 
radnorCommented:
Yeah, I did not know if the person who asked the question did the parens to make it easier to read...  I was just following along....
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now