# Open links in same page/frame

**URL:** <https://forum.kirupa.com/t/open-links-in-same-page-frame/263109>\
**Category:** programming\
**Created:** [June 12, 2008, 4:55pm UTC](https://forum.kirupa.com/t/open-links-in-same-page-frame/263109 "2008-06-12T16:55:06Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![melanie\_bund](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@melanie\_bund](https://forum.kirupa.com/u/melanie_bund)\
**Post date:** [June 12, 2008, 4:55pm UTC](https://forum.kirupa.com/t/open-links-in-same-page-frame/263109/1 "2008-06-12T16:55:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![djheru](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/djheru/32/3190_2.png) [@djheru](https://forum.kirupa.com/u/djheru)\
**Post date:** [June 13, 2008, 3:39pm UTC](https://forum.kirupa.com/t/open-links-in-same-page-frame/263109/2 "2008-06-13T15:39:21Z")

</div>

Navigation:

```auto

<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)

```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!";
}

```

if you don’t want the pages to be named numerically, just make sure to put the string value in quotes like

```php
case 'home':

```

---

<div class="post-metadata">

**Author:** ![melanie\_bund](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@melanie\_bund](https://forum.kirupa.com/u/melanie_bund)\
**Post date:** [June 18, 2008, 4:57pm UTC](https://forum.kirupa.com/t/open-links-in-same-page-frame/263109/3 "2008-06-18T16:57:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![actionAction](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/actionaction/32/3987_2.png) [@actionAction](https://forum.kirupa.com/u/actionAction)\
**Post date:** [June 18, 2008, 5:06pm UTC](https://forum.kirupa.com/t/open-links-in-same-page-frame/263109/4 "2008-06-18T17:06:42Z")

</div>

Please post your revised code.

---

<div class="post-metadata">

**Author:** ![melanie\_bund](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@melanie\_bund](https://forum.kirupa.com/u/melanie_bund)\
**Post date:** [June 19, 2008, 12:26pm UTC](https://forum.kirupa.com/t/open-links-in-same-page-frame/263109/5 "2008-06-19T12:26:58Z")

</div>

\<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

---

<div class="post-metadata">

**Author:** ![Maqrkk](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Maqrkk](https://forum.kirupa.com/u/Maqrkk)\
**Post date:** [June 19, 2008, 12:45pm UTC](https://forum.kirupa.com/t/open-links-in-same-page-frame/263109/6 "2008-06-19T12:45:12Z")

</div>

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:

```auto

<?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!";
} ?>

```

---

<div class="post-metadata">

**Author:** ![melanie\_bund](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@melanie\_bund](https://forum.kirupa.com/u/melanie_bund)\
**Post date:** [June 19, 2008, 2:52pm UTC](https://forum.kirupa.com/t/open-links-in-same-page-frame/263109/7 "2008-06-19T14:52:54Z")

</div>

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\>";  
} ?\>

---

<div class="post-metadata">

**Author:** ![hl1](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/hl1/32/849_2.png) [@hl1](https://forum.kirupa.com/u/hl1)\
**Post date:** [June 19, 2008, 3:01pm UTC](https://forum.kirupa.com/t/open-links-in-same-page-frame/263109/8 "2008-06-19T15:01:07Z")

</div>

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]

```auto
 tags to highlight your code, it'd become much more apparent.
```

---

<div class="post-metadata">

**Author:** ![Charleh](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@Charleh](https://forum.kirupa.com/u/Charleh)\
**Post date:** [June 19, 2008, 3:11pm UTC](https://forum.kirupa.com/t/open-links-in-same-page-frame/263109/9 "2008-06-19T15:11:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Maqrkk](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Maqrkk](https://forum.kirupa.com/u/Maqrkk)\
**Post date:** [June 19, 2008, 3:41pm UTC](https://forum.kirupa.com/t/open-links-in-same-page-frame/263109/10 "2008-06-19T15:41:31Z")

</div>

Well either way. Just instead of

```auto
echo "Hello";

```

write this:

```auto
echo 'Hello';

```

with single quotes.

---

<div class="post-metadata">

**Author:** ![djheru](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/djheru/32/3190_2.png) [@djheru](https://forum.kirupa.com/u/djheru)\
**Post date:** [June 19, 2008, 5:46pm UTC](https://forum.kirupa.com/t/open-links-in-same-page-frame/263109/11 "2008-06-19T17:46:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![melanie\_bund](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@melanie\_bund](https://forum.kirupa.com/u/melanie_bund)\
**Post date:** [June 19, 2008, 5:46pm UTC](https://forum.kirupa.com/t/open-links-in-same-page-frame/263109/12 "2008-06-19T17:46:42Z")

</div>

Hi  
I used included instead and it WORKS  
thanks for everyones help  
Melanie
