Jump to content


Photo

php if statement in html page


  • Please log in to reply
7 replies to this topic

#1 mbodamer

mbodamer

    Newbie

  • New Members
  • Pip
  • 2 posts

Posted 06 February 2013 - 02:35 PM

Hi,
I am trying tomimic this functionality:

<?php if($listing['bedrooms']) : ?><b>Bedrooms:</b> <?php echo $listing['bedrooms'] ?><br/> <?php endif; ?>

that is on a working site but I do not have the variable defined yet. I have a program that generates tags like this: {bedrooms}

so I am seeking to match IF bedrooms=3 (for example) then display 3bed.jpg

this is what I was trying but it failed miserably:

<?php $name = {name};  if($name == "joe") : ?><img src="joe.jpg"><?php endif; ?>

hopefully you can follow my wayward logic.
Thanks

#2 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 06 February 2013 - 02:45 PM

{name} is not valid PHP. What are you trying to set $name to?
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#3 mbodamer

mbodamer

    Newbie

  • New Members
  • Pip
  • 2 posts

Posted 06 February 2013 - 03:42 PM

Well like I said... {name} is a tag that is generated from a program that I can simply put on the HMTL page anywhere and it will print the value of {name}. So I need a way to see what that value is, and then if it matches what I want, print something if not ignore it.

if I just put {name} on the page it will print "joe" for example.

#4 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 06 February 2013 - 03:44 PM

That's doesn't make it valid PHP. What "puts" joe into {name}? What program are you using?
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#5 Love2c0de

Love2c0de

    Advanced Member

  • Members
  • PipPipPip
  • 366 posts
  • LocationThe Pleiades
  • Age:23

Posted 07 February 2013 - 06:13 AM

Wouldn't PHP interpret {name} as a constant?

Regards,

L2c.

#6 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 07 February 2013 - 08:48 AM

Nope, it produces a syntax error for an unexpected {.
Easily testable by yourself, btw, by running one line via the PHP CLI shell.

Edited by Christian F., 07 February 2013 - 08:49 AM.

Keeping it simple.

#7 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 07 February 2013 - 09:26 AM

Good job answering the important questions. Good luck.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#8 Love2c0de

Love2c0de

    Advanced Member

  • Members
  • PipPipPip
  • 366 posts
  • LocationThe Pleiades
  • Age:23

Posted 07 February 2013 - 12:55 PM

Nope, it produces a syntax error for an unexpected {.
Easily testable by yourself, btw, by running one line via the PHP CLI shell.


Wow I was never aware we could run php from the command line. I was at work when I replied to that, usually I would just test something before asking a question etc.

So eunning PHP from the command line means we don't need a local server for example to run PHP scripts? I'm going to give the php.net a thorough read regarding CLI when I get back.

I might do a bit of PHP in my break now, they already got n++ installed ;D

Kind regards,

L2c.

Edited by Love2c0de, 07 February 2013 - 12:57 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com