Also, when writing HTML (or anything else that may have quote marks), it's usually much easier to use the HEREDOC notation:
$string = <<< HTML
Hello, I'm using "quotes" left and right, and I don't need to escape them.
I can still use $variables in my text,
or even {$nested['array']['indexes']}.
A "HEREDOC" is like a "double-quote" string,
but it starts with three less-than brackets ( <<< )
followed by a token (anything; I used "HTML" here)
and ends when the token appears at the beginning of a line
(by itself, no indentation at all),
with a semicolon by itself on the next line.
Have a try!
HTML
;
<?php if ( is_page_template('template-fullwidth.php') ) { ?>
your html here
<?php } elseif ( is_page_template('template-planes.php') ) { ?>
your html here
<?php } else { ?>
your html here
<?php } ?>
Thank you for all your answers ( @Rai, @traq, @AndyHowells ). One problem that I keep on encountering with that code is the pure html works and does swap image but when I try to incorporate it inside PHP, it doesn't work anymore. That is why i'm looking for a work around on how to write it inside PHP because I will be getting the image source from a database if only those code will work. :( Please help...
@traq, Sorry if I sound a little confusing. The pure HTML markup with a little javascript I posted does a "swap image". The small/thumbnail images when clicked , a bigger version of that image will appear below. But then when I try to rewrite the code inside PHP and run it in a browser, it doesn't do anything when you click the thumbnail image but I didn't get any error messages.
<?php
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("motoactiv-db") or die (mysql_error());
$sql = "Select * FROM products";
$result = mysql_query($sql);
while($record=mysql_fetch_array($result))
{
?>
<img src="images/helmets/<?php echo $record['side_view']?>" width="100"
onmousedown="document.images['main'].src='images/helmets/<?php echo $record['top_view']?>'">
</br>
<img name="main">
<?php
}
?>
I still haven't figured out the problem with this because when I tested it out in Firefox and IE it works just fine but when I tried it with Chrome, it doesn't make the bigger image come out, it is as if no javascript was implemented. @traq
Why are you escaping the quotes? You don't need to do that. You only need to do that when the quotes are the same as the surrounding quotes. If your html is inside double quotes, you don't need to escape single quotes.
<?php
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("motoactiv-db") or die (mysql_error());
$sql = "Select * FROM products";
$result = mysql_query($sql);
while($record=mysql_fetch_array($result)) : ?>
<img src="images/helmets/<?php echo $record['side_view']?>" width="100"
onmousedown="document.images['main'].src='images/helmets/<?php echo $record['top_view']?>'" />
<br />
<img name="main" />
<?php endwhile ?>
I've just taken your code and modified it slightly. You hadn't ended your <img> tags, that could've been the source of your problem. I would also move the JS to a separate file and call it by ID.
The PHP syntax used is the alternate form which makes it slightly easier to read.
How do I write this code inside PHP echo " ";
I tried writing it just like the above code but it doesn't work.
Need to add a ; to the end of your echo after the closing quote mark.
just so you know, this:
are exactly equivalent.
Also, when writing HTML (or anything else that may have quote marks), it's usually much easier to use the HEREDOC notation:
Try this:
Thank you for all your answers ( @Rai, @traq, @AndyHowells ). One problem that I keep on encountering with that code is the pure html works and does swap image but when I try to incorporate it inside PHP, it doesn't work anymore. That is why i'm looking for a work around on how to write it inside PHP because I will be getting the image source from a database if only those code will work. :( Please help...
Well, what do you mean by "doesn't work"?
What actually happens vs. what you expected?
Did you make sure error reporting is enabled, and do you get any error messages?
@traq, Sorry if I sound a little confusing. The pure HTML markup with a little javascript I posted does a "swap image". The small/thumbnail images when clicked , a bigger version of that image will appear below. But then when I try to rewrite the code inside PHP and run it in a browser, it doesn't do anything when you click the thumbnail image but I didn't get any error messages.
@ajnoguerra what does the output HTML look like?
@traq, I'm glad you're really trying to help me. Here's the output >>> swap image
That seems to work as expected, unless I misunderstand your problem.
Are you sure you posted the output HTML (i.e., the HTML that is generated by PHP and demonstrates your problem)?
I still haven't figured out the problem with this because when I tested it out in Firefox and IE it works just fine but when I tried it with Chrome, it doesn't make the bigger image come out, it is as if no javascript was implemented. @traq
@ajnoguerra - see my comment in your other thread.
Why are you escaping the quotes? You don't need to do that. You only need to do that when the quotes are the same as the surrounding quotes. If your html is inside double quotes, you don't need to escape single quotes.
wow such a great info. http://adiphene.webs.com
I've just taken your code and modified it slightly. You hadn't ended your <img> tags, that could've been the source of your problem. I would also move the JS to a separate file and call it by ID.
The PHP syntax used is the alternate form which makes it slightly easier to read.