Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 30th Apr 2016, 09:04 AM   #1
Active Warrior
 
Join Date: 2010
Posts: 31
Thanks: 16
Thanked 1 Time in 1 Post
Lightbulb
PHP Help Please
Share on: 
fb share twitter share gplus share more share

Hi everyone,

I need a nudge in the right direction if anyone can help please

I am trying to output different H1 headers on my page based on the page id.

For example, if someone lands on my page

example.com/landingpage.php?id=1

I would like to display H1 version 1.

landingpage.php?id=2 would show H1 version 2 ETC. So far I have

HTML Code:
<?php

$h1=$_GET['id'];

if ($h1 == "1") {
    echo "headline 1";
}
if ($h1 == "2") {
    echo "headline 2";
}

elseif ($h1 == "3") {
    echo "headline 3";
}

elseif() blocks
else {
    echo "default headline";
}

?>
Now I want to output the title on my page like this

HTML Code:
<h1><?php echo($_GET["h1"]) ?></h1>
But I think the echo is making it display at the top of my page

Can anyone help me out please?

Thanks

Check out my blog - www.techableme.com
mikeboffer is offline  
Unread 30th Apr 2016, 01:37 PM   #2
Active Warrior
 
WebMarketingTool's Avatar
 
Join Date: 2016
Location: Wildwood, GA
Posts: 37
Thanks: 4
Thanked 6 Times in 6 Posts
Default
Re: PHP Help Please
Share on: 
fb share twitter share gplus share more share

Use this php code:
<?php

if (isset($_GET["id"]) $h1=$_GET['id'];
else $h1 = "";

if ($h1 == "1") {
$headline = "headline 1";
}
else if ($h1 == "2") {
$headline = "headline 2";
}
else if ($h1 == "3") {
$headline = "headline 3";
}

else {
$headline = "default headline";
}
?>

And then to echo use:
<h1><?php echo $headline; ?></h1>
WebMarketingTool is offline  
Unread 1st May 2016, 02:48 AM   #3
Bananas are Yellow!
Registered Member
War Room Member
 
David Beroff's Avatar
 
Join Date: 2013
Location: Wyoming, PA, USA
Posts: 1,046
Thanks: 2,549
Thanked 1,600 Times in 928 Posts
Blog Entries: 4
Default
Re: PHP Help Please
Share on: 
fb share twitter share gplus share more share

Originally Posted by WebMarketingTool View Post

<h1><?php echo $headline; ?></h1>
Yep! Also, an often-used (and intuitive) shortcut for this is:

Code:
<h1><?= $headline ?></h1>

Put MY voice on YOUR video: AwesomeAmericanAudio.com
David Beroff is offline  
Unread 2nd May 2016, 06:18 AM   #4
Warrior Member
 
Brendan Edmonds's Avatar
 
Join Date: 2016
Posts: 3
Thanks: 0
Thanked 2 Times in 2 Posts
Default
Re: PHP Help Please
Share on: 
fb share twitter share gplus share more share

Originally Posted by David Beroff View Post

Yep! Also, an often-used (and intuitive) shortcut for this is:

Code:
<h1><?= $headline ?></h1>
Please note, that <?= will only work if short_open_tag is enabled prior to PHP 5.4.0.
Brendan Edmonds is offline  
The Following User Says Thank You to Brendan Edmonds For This Useful Post:
Closed Thread


Bookmarks

Tags
echo, php


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 11:43 PM.