lcot Posted June 17, 2013 Share Posted June 17, 2013 To get it out of the way, I am learning php as I go and I am new to it. I am really trying to get my hands dirty in it on this project to learn and to make my life easier! I have a scenario, and I would love for someone to help me out through it and point me in the right direction. My scenario is: I have a latest news page on my 'static' website. I am using php includes on the header, navbar and footer for every page. I am using includes to grab the latest news information I have in assets/news/form/news1.php. This is the following: <?php if (!defined("ACCESS")) { die ("Don't waste your time trying to access this file!! Please head to the families relief home page and donate!!"); } ?> <?php $header = 'Article Header'; $date = 'June 1st 2013'; $url = '/news/articleName'; $body = 'Body in HTML'; ?> I then have another file in assets/news/news1.php containing: <div id="appeal3" class="row-fluid"> <div class="well span12"> <div class="span3"> <div class="thumbnail"> <a href="<?php echo $url ?>"><img src="/img/news-blank.jpg"></a> </div> </div><!-- span3 --> <div class="span9 appeals"> <p class="app-date"><?php echo $date?></p> <a href="<?php echo $url ?>"><h3><?php echo $header ?></h3></a> <p><?php echo substr($body, 0, 200) ?><span class="readmore"><a href="<?php echo $url ?> "> ...Read More ></a></span></p> </div><!-- span9 --> </div><!-- well span12 --> </div><!-- appeal# --> I then use the following code on my news overview page at /news/index.php to display the html with the variables entered: <?php include("$_SERVER[DOCUMENT_ROOT]/assets/news/news1.php"); ?> So what this gives me is an overview page, with the news article displayed around a wrapper in overview view. I then have another page when the overview 'read more' is clicked. Within this page, I have a full view news article page with a wrapper where I can echo the variables in. Wha La! That is my news article structure.. Long winded isn't it! Now, what I want!! I want to be able to include the variables from an article into my overview page and include the 2nd block of code above as the template. I then want the articles to fill out the variables. However, I have 5 articles on this page with identical variables. What is the best and most efficient way to do this?? Secondly, I have a full-view article page. How can I use this page as a template, and change the php it gets it's variables from. But, I don't want to create a new php page every time I have a new article. What I had in mind, is something like the following: domain.com/news/article/index.php?news1 I have been reading up on passing variables in a URL. I want to expand my knowledge on this. Could this be the solution to my problem. My issue is that I have NO idea how to go about this? Can someone please lecture me to solve this and hopefully teach me a little in between! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/279270-php-variables-url-assistance-needed/ Share on other sites More sharing options...
ginerjm Posted June 17, 2013 Share Posted June 17, 2013 I think you're describing have <a> tags around your "variables" so that when they click on one of them you can take them to the article they want to see. No? <a href=(url/pagename?article=$var1)>variable1</a> <a href=(url/pagename?article=$var2>>variable2</a> where $var1 and $var2, etc are set to some keyword or filename that tells your receiving page what to do. Your receiving page simply does: $article = $_GET['article']; to get the value and then it runs with that info. Hope I'm close. Quote Link to comment https://forums.phpfreaks.com/topic/279270-php-variables-url-assistance-needed/#findComment-1436438 Share on other sites More sharing options...
lcot Posted June 17, 2013 Author Share Posted June 17, 2013 Thanks for the response!! Yes, you are spot on with what you have just said. That is exactly what I want to happen. I just don't have the experience to understand how to get the two pages to talk to each other. So, my news article link will be the variable that is set in the article php file. And the receiving page, which is the article page template will know which php file to grab it's variables from. I have a folder full of articles. So how is best to go about this? Quote Link to comment https://forums.phpfreaks.com/topic/279270-php-variables-url-assistance-needed/#findComment-1436489 Share on other sites More sharing options...
ginerjm Posted June 17, 2013 Share Posted June 17, 2013 The first page does a scandir to get all the article/file names and the keywords(?) and the second page processes one selected article and displays the entire contents. No? Read up on scandir and fopen - two php functions that will do what you want to do Quote Link to comment https://forums.phpfreaks.com/topic/279270-php-variables-url-assistance-needed/#findComment-1436496 Share on other sites More sharing options...
lcot Posted June 18, 2013 Author Share Posted June 18, 2013 Thanks ginerjm! I'll do that now! Quote Link to comment https://forums.phpfreaks.com/topic/279270-php-variables-url-assistance-needed/#findComment-1436578 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.