Hi
I want to do a web page with say 6 vertical links, these links open 6 seperate pages within 1 same part/table in the webpage, can it be done using php, if so could do with step by step instruction
Thanks
Navigation:
<ul>
<li><a href="index.php?page=1">Page 1</a></li>
<li><a href="index.php?page=2">Page 2</a></li>
<li><a href="index.php?page=3">Page 3</a></li>
<li><a href="index.php?page=4">Page 4</a></li>
<li><a href="index.php?page=5">Page 5</a></li>
<li><a href="index.php?page=6">Page 6</a></li>
</ul>
Page (Place this in the div where you want the content to be displayed)
switch ($_GET['page'])
{
case 2:
echo "Welcome to page 2!";
break;
case 3:
echo "Welcome to page 3!";
break;
case 4:
echo "Welcome to page 4!";
break;
case 5:
echo "Welcome to page 5!";
break;
case 6:
echo "Welcome to page 6!";
break;
default:
echo "Welcome to page 1!";
}
if you don’t want the pages to be named numerically, just make sure to put the string value in quotes like
case 'home':
hi
i keep on getting an error with the code above -
Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ';'
I have named the pages i want to call up eg: “page1.php”, but cant seem to get them, just get the “Welcome to page …!”- what am i doing wrong here
thanks
Please post your revised code.
<ul id=“menu”>
<li><a href=“treatments.php?page=1”>Page 1</a></li>
<li><a href=“treatments.php?page=2”>Page 2</a></li>
<li><a href=“treatments.php?page=3”>Page 3</a></li>
<li><a href=“treatments.php?page=4”>Page 4</a></li>
<li><a href=“treatments.php?page=5”>Page 5</a></li>
<li><a href=“treatments.php?page=6”>Page 6</a></li>
</ul>
<?php switch ($_GET[‘page’])
{
case 2:
echo “Welcome to page 2!”;
break;
case 3:
echo "Welcome to page 3!";
break;
case 4:
echo "Welcome to page 4!";
break;
case 5:
echo "Welcome to page 5!";
break;
case 6:
echo "Welcome to page 6!";
break;
default:
echo "Welcome to page 1!";
} ?>
Havent changed anything - want the code to pick up different pages - page1.php, page2.php… and replace one after another when you click on the menu
You are talking about page1.php and page2.php. Why? I thought the purpose was to display the site content inside the switch part, like this:
<?php
$page = $_GET['page'];
echo "Welcome to page " . $page . "!<br />";
switch ($page)
{
case 2:
echo "Page 2 is about ...";
break;
case 3:
echo "Page 3 is about ...";
break;
case 4:
echo "Page 4 is about ...";
break;
case 5:
echo "Page 5 is about ...";
break;
case 6:
echo "Page 6 is about ...";
break;
default:
echo "This is the first page!";
} ?>
hi, well i have tried the code and i still get an error report when trying to open page
Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’ in /homepages/15/d244336518/htdocs/lucysbeautystudio/treatments.php on line 54 - which is the line after case 2:
case 2:
echo “<div class=“image-right”><img src=”…/www/images/b09.jpg" width=“200” height=“200” /></div>
below is the code
<?php
$page = $_GET[‘page’];
echo “Welcome to page " . $page . “!<br />”;
switch ($page)
{
case 2:
echo “<div class=“image-right”><img src=”…/www/images/b09.jpg” width=“200” height=“200” /></div> <p><strong>MANICURES</strong></p>
<p>AashhFJH Jfjkh hajkfhkjafh sdh gjkfhgkshgk kjdsh gkjdsklh fgjdshfg hsdgkl gjkhsdgkjhdfskj dghjdg hgdghdhsgkjldhsfgkjhd djkshg kdsfgkdsgdklgjhsdkgh dks ggdjsghkjdhfsgkhdshgjkl ddfg dlgjh dgdlsgh dlkjsgh ds ghkldjsghlkjdsjkhgdsk kldjsh dhjkhdsfjk dfghfgjhdkgh g </p>
<P>dfshjdhsflfghjdshgfghjkdfhgkjhjkdfhgkdhslghdsfg
<P>sgdhgjkldshgklhsdgjhdsfhgdhgjkhdsfghkjdgsjkgh dfskhgsdkhg j kjsd kjd skhg skgh kjds kl kjhkdshgjkhgdskshdlg skdh kjlsdfgk h hsdgkl gjkhsdgkjhdfskj dghjdg hgdghdhsgkjldhsfgkjhd djkshg kdsfgkdsgdklgjhsdkgh dks ggdjsghkjdhfsgkhdshgjkl ddfg dlgjh dgdlsgh dlkjsgh ds ghkldjsghlkjdsjkhgdsk kldjsh dhjkhdsfjk dfghfgjhdkgh g </P>";
break;
case 3:
echo “Page 3 is about …”;
break;
case 4:
echo “Page 4 is about …”;
break;
case 5:
echo “Page 5 is about …”;
break;
case 6:
echo “Page 6 is about …”;
break;
default:
echo “<div class=“image-right”><img src=”…/www/images/b09.jpg" width=“200” height=“200” /></div>
<p><strong>PEDICURES</strong></p>
<p>AashhFJH Jfjkh hajkfhkjafh sdh gjkfhgkshgk kjdsh gkjdsklh fgjdshfg hsdgkl gjkhsdgkjhdfskj dghjdg hgdghdhsgkjldhsfgkjhd djkshg kdsfgkdsgdklgjhsdkgh dks ggdjsghkjdhfsgkhdshgjkl ddfg dlgjh dgdlsgh dlkjsgh ds ghkldjsghlkjdsjkhgdsk kldjsh dhjkhdsfjk dfghfgjhdkgh g </p>
<P>dfshjdhsflfghjdshgfghjkdfhgkjhjkdfhgkdhslghdsfg
<P>sgdhgjkldshgklhsdgjhdsfhgdhgjkhdsfghkjdgsjkgh dfskhgsdkhg j kjsd kjd skhg skgh kjds kl kjhkdshgjkhgdskshdlg skdh kjlsdfgk h hsdgkl gjkhsdgkjhdfskj dghjdg hgdghdhsgkjldhsfgkjhd djkshg kdsfgkdsgdklgjhsdkgh dks ggdjsghkjdhfsgkhdshgjkl ddfg dlgjh dgdlsgh dlkjsgh ds ghkldjsghlkjdsjkhgdsk kldjsh dhjkhdsfjk dfghfgjhdkgh g </P>";
} ?>
You need to comment out any nested quotation marks. For example [font=Courier New]echo “<htmltag property=“lala”>”;[/font]. Alternatively, you can use Heredoc form (google it), or you can use single quotes (’) on either the inside or outside, so the quote styles are different.
Also, use the [ php ]
tags to highlight your code, it'd become much more apparent.
Why don’t you just use includes instead?
include(“page1.php”); instead of embedding/echoing the page content. That way you won’t get these errors.
If you have one main file with this code in and then create each page as a seperate PHP file (page1.php, page2.php etc) then just use
include(“pagexxx.php”); instead of your echo statements.
Well either way. Just instead of
echo "Hello";
write this:
echo 'Hello';
with single quotes.
Yes, if you are using double quotes on your echo statement, you need to escape any double quotes within the string itself by placing a \ before them.
I always use the method described by Charleh, using include() statements to load the appropriate content. That way, you don’t have to worry about it. You also might want to look into HEREDOC syntax, which is handy if you want to assign a very long string to a php variable.
Hi
I used included instead and it WORKS
thanks for everyones help
Melanie