Forum Moderators: coopster

Message Too Old, No Replies

php links and content - help please

         

dubbed

6:50 am on Apr 24, 2004 (gmt 0)

10+ Year Member



i am new to php and know some basics, so please excuse my ignorance. any help with this would be greatly appreciated.

this is the basic layout of a particular page:

articles.php

-----------------------------
header
-----------------------------
link to article1
link to article2
link to article3
link to article4
etc
-----------------------------
footer
-----------------------------

what i want to achieve is - all of the content for links 1-4 are within articles.php. when a link is clicked, the links would disappear and the article content displayed.

is this possible?

thank you in advance.

:)

jatar_k

4:58 pm on Apr 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld dubbed,

I think in this instance you could use a variable in the url to display the appropriate article once clicked.

your links could look something like this

<a href="articles.php?article=1">article1</a>

then do a test to see is the variable is set

if (!isset($_GET['article']) ¦¦ $_GET['article'] == "") {
// echo all links
} else {
// echo individual content
}

dubbed

5:17 pm on Apr 24, 2004 (gmt 0)

10+ Year Member



thanks jatar.

once i have done the code for the echo, what is the code for the contect?

your help is very much appreciated.

dubbed

5:18 pm on Apr 24, 2004 (gmt 0)

10+ Year Member



/content

jatar_k

6:24 pm on Apr 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it depends actually

is all the content smashed into the one file or is the actual content in seperate files?

If the content is stored in seperate files you could do

} else { 
$articlepage = "article" . $_GET['article'] . ".html";
include $articlepage;
}

this would assume that the articles are located in the same directory and are named article1.html, article2.html etc.

or if all the content is smashed in there you could use a switch

} else { 
switch ($_GET['article']) {
case 1:
// article1 content
break;
case 2:
// article2 content
break;
case 3:
// article3 content
break;
}
}

one case for each article, though that may make that file fairly huge as time goes on

dubbed

9:06 pm on Apr 24, 2004 (gmt 0)

10+ Year Member



i have saved the following as article.php to test

i'm getting a parse error on line 7:

<a href="articles.php?article=1">article1</a>
<a href="articles.php?article=2">article2</a>
<a href="articles.php?article=3">article3</a>

<?php

if (!isset($_GET['article']) ¦¦ $_GET['article'] == "") {
// echo all links
} else { switch ($_GET['article']) {
case 1:
article1 content
break;
case 2:
article2 content
break;
case 3:
article3 content
break; } }

?>

dubbed

8:36 am on Apr 25, 2004 (gmt 0)

10+ Year Member



jatar. you are a star! thank you for your help.

i have fixed the script, and yes it does work :)

now the task of entering 61 articles into this page. ugh.

hakre

1:59 pm on Apr 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi dubbed,

checkout the nice include() [php.net] function. you can simply load in each article, so you can divide the one-big-file into manies.

--hakre

dubbed

4:39 pm on Apr 28, 2004 (gmt 0)

10+ Year Member



thanks to you both! a credit to this community.