pnrule Posted July 7, 2008 Share Posted July 7, 2008 I am trying to do something where I have a bunch of HTML files containing articles, and includes to place them in one page. IE the page is index.php and theres articles 1.html through 50.html How do I use links to display a certain article with next and previous article buttons and such? I think includes are what I need? Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/ Share on other sites More sharing options...
Lodius2000 Posted July 7, 2008 Share Posted July 7, 2008 I would put the articles or urls to the articles in db and then make paginated links from that EDIT: if you have the php cookbook, recipe 10.13 would help with the pagination Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-583206 Share on other sites More sharing options...
pnrule Posted July 7, 2008 Author Share Posted July 7, 2008 Hey, could you dumb it down a notch? Haha. I'm just learning. But basically what you are saying is I should store URLS to a DB and then call the urls from the DB and use an include to display it? Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-583220 Share on other sites More sharing options...
CMC Posted July 7, 2008 Share Posted July 7, 2008 You've got part of it right. Store the URL's in the DB, then call the previous and next URL from the DB to create previous/next links. You'll have to order the articles somehow and figure out how to number them. Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-583226 Share on other sites More sharing options...
pnrule Posted July 7, 2008 Author Share Posted July 7, 2008 I'll read up on all that stuff for a while and experiment and tell ya what I get. Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-583228 Share on other sites More sharing options...
pnrule Posted July 11, 2008 Author Share Posted July 11, 2008 How do I get this to work? I believe it won't work because the include won't do a variable. There's something else wrong I'm not aware of also. <html> <body> <?php if (isset($_GET['a'])) { $a = $_GET['a']; } ?> If this works, text appears here:<br /> <?php include("$a.html");?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-587159 Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 It WILL include a variable, but you should NEVER include something like that. It's susceptible to being used for malicious purposes. You need to do some verifications. Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-587163 Share on other sites More sharing options...
xtopolis Posted July 11, 2008 Share Posted July 11, 2008 --edit-- nevermind, I didn't read "pagination" Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-587233 Share on other sites More sharing options...
pnrule Posted July 11, 2008 Author Share Posted July 11, 2008 So that should work? Because I tested it in WAMP and nothing happened. Really? I had no idea. It's not sensitive or information, it's just going to be used to display an article. So what do I need to do to verify it? Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-587310 Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 They can enter anything, and could technically send over an external link which opens up some files or deletes some files. Verify EVERY PIECE of input you ever receive in a script. Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-587311 Share on other sites More sharing options...
pnrule Posted July 11, 2008 Author Share Posted July 11, 2008 YAY! It works! I think I'm starting to get the hang of this crazy language. <html> <body> <?php if (isset($_GET['a']) && is_numeric ($_GET['a'])) { $a = $_GET['a']; } else { echo "Sorry, you must have followed a dead link. Please return to the home page."; } if (isset($a)) { echo "If this works, variable value here: "; echo $a; echo "And included page here: "; include("$a.html"); } ?> </body> </html> Although, there is one problem. For example, if I'm displaying 1.html, it will output: If this works, variable value here: 1And included page here: 1.html content How do I make it output like this? If this works, variable value here: 1 And included page here: 1.html content Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-587632 Share on other sites More sharing options...
craygo Posted July 11, 2008 Share Posted July 11, 2008 use breaks echo "If this works, variable value here:<br />\n"; echo $a."<br />\n"; echo "And included page here: <br />\n"; include("$a.html"); Ray Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-587647 Share on other sites More sharing options...
pnrule Posted July 11, 2008 Author Share Posted July 11, 2008 Thanks! Last question and I should (knock on wood) know enough for my web page. A in my examples stands for an article number. At the bottom I will have a next and previous link. Previous will be $p and next will be $n. So along these lines: <?php if ($a>1) { $p = $a-1; } $n = $a+1; ?> How do I use these values to make links? Will this work? <?php if ($a>1) { $p = $a-1; echo '<a href="$p.html">Previous</a><br />'; } $n = $a+1; echo '<a href="$n.html">Next</a><br />'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-587665 Share on other sites More sharing options...
craygo Posted July 11, 2008 Share Posted July 11, 2008 Got the right idea, but since you are using single quotes, all variables inside are seen as they are not as the variable. You need to come out of the single quotes to get the value. <?php if ($a>1) { $p = $a-1; echo '<a href="'.$p.'.html">Previous</a><br />'; } $n = $a+1; echo '<a href="'.$n.'.html">Next</a><br />'; ?> Ray Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-587671 Share on other sites More sharing options...
pnrule Posted July 11, 2008 Author Share Posted July 11, 2008 Ah, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-587686 Share on other sites More sharing options...
xtopolis Posted July 12, 2008 Share Posted July 12, 2008 Also, you need to set a floor for your article count. Obviously there won't be a 0 article, but you don't want a link that shows "Article 0" because of the counter. You can either set it to look to the max count of articles (which would be 50<->0<->1) or just say : if($a)== 0; display a greyed out link that isn't clickable, or nothing at all. Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-588105 Share on other sites More sharing options...
pnrule Posted July 12, 2008 Author Share Posted July 12, 2008 Exactly. You must have missed it. <?php if ($a>1) { $p = $a-1; echo '<a href="'.$p.'.html">Previous</a><br />'; } $n = $a+1; echo '<a href="'.$n.'.html">Next</a><br />'; ?> So it's checking to make sure $a is greater than one and if it's not than it will not display a previous link. And eventually I'll add this: if ($a< some number) { $n = $a+1; echo '<a href="'.$n.'.html">Next</a><br />'; } So I believe that's it. PHP isn't too hard Quote Link to comment https://forums.phpfreaks.com/topic/113502-solved-php-to-display-certain-content-on-a-page/#findComment-588507 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.