tripleaaa Posted May 24, 2007 Share Posted May 24, 2007 I hope some one can help. I'm not a guru on PHP. I'm creating a web site for a non-profit org. The org. has alot of pages with little text content on them. I wanted to create 1 (one) php, with various content. I would create links on the page and when clicked that section would show. I had something like this a very long time ago and can't find it and asking if someone can point me to a web site with a tutorial on this. Hope someone can help. tks tripleaaa Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/ Share on other sites More sharing options...
taith Posted May 24, 2007 Share Posted May 24, 2007 for example... <a href="?page=test">test</a><a href="?page=1">1</a> <? switch($_GET ){ case "test": echo 'test content'; break; case "1": echo 'page 1 content'; break; default: echo 'default content'; break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/#findComment-260914 Share on other sites More sharing options...
marmite Posted May 24, 2007 Share Posted May 24, 2007 this shouldn't be a problem at all, i've done a fair few of my pages like this. so, you can change the text like below; the links are e.g. www.cardsunlimited.com/greetingscards.php?purpose=officegreetingcards Just use if statements coupled with links to e.g. www.example.com/page.php?customer=charity that sets $_GET['customer'] to 'charity'. on page.php, you use an if statement to get the $_GET value and echo text appropriately. if you get stuck i can give you more php by PM <div id="middle"> <table border="0" cellpadding="0" cellspacing="0"> <tr><td> <?php if ($_GET['purpose']=='officegreetingcards') { echo '<div id="h1"> Office greeting cards </br></div> <div id="blurb">Are you the person who has to pop out and buy all the greeting cards for people at work? Are you paying £2 a pop? Crazy, isn’t it? </br></br> On this site, you can buy individual greeting cards for £1.20 each, packs of 5 mixed cards for £1 per card, or packs of 25 same-design cards for 50p per card. Click on a design you like, and the options - including mixed packs - will pop up, as if by magic!</br></br>If you know you would like only Birthday, or Get Well cards, please use the Message dropdown to your left.'; } elseif ($_GET['purpose']=='hotelgreetingcards') { echo '<div id="h1"> Hotel greeting cards </br></div> <div id="blurb">Our greeting cards are used in several prestigious hotels within the UK. </br></br> Greeting cards may be given to guests to welcome them, or to help celebrate a guest’s birthday or anniversary. Prices start from just 50p. Please click on a design you like to display the packaging options and prices. If you would like to narrow down the results, please use the dropdowns to your left.'; } else { echo '<div id="h1"> Greeting cards </br></div> <div id="blurb">We stock over 80 designs of greeting cards, all photographic, all square, and all available to you as a consumer from 50p, or as a retailer from 65p (individually wrapped in cellophane). Click on any of the images to see whether the card is available blank or messaged, and to see what the pricing options are.</div>'; } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/#findComment-260915 Share on other sites More sharing options...
tripleaaa Posted May 25, 2007 Author Share Posted May 25, 2007 tks marmite and taith, taking the codes you have mentioned. I create example links: Home, About us, Contact Us etc.... What statement would I use to link the content. Also can I add tables and images in the echo statment. Do not mean to be dumb on this.. Just not an expert. Pls confirm And tks for helping me out this a great ++++++++++ tks all trippleaaa Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/#findComment-261192 Share on other sites More sharing options...
Dragen Posted May 25, 2007 Share Posted May 25, 2007 you can echo any html in php. So long as you put it all in and escape any neccessary characters then you should be fine. Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/#findComment-261195 Share on other sites More sharing options...
tripleaaa Posted May 25, 2007 Author Share Posted May 25, 2007 marmite i want to send pm to you but forum states that i cannot do it. is there any other way for me to contact you? tripleaaa Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/#findComment-261237 Share on other sites More sharing options...
tripleaaa Posted May 25, 2007 Author Share Posted May 25, 2007 dear marmite, i figured the links out as per your below explanation and playing around with it. FANTASTICO!.... Great forum quick quick reponse. thank you thank you thank you tripleaaa Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/#findComment-261242 Share on other sites More sharing options...
tripleaaa Posted May 25, 2007 Author Share Posted May 25, 2007 Another quick question are these links search engine friendly to SEO? Pls advise. tks tripleaaa Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/#findComment-261243 Share on other sites More sharing options...
marmite Posted May 25, 2007 Share Posted May 25, 2007 search engines read the resulting html, not the php that spews out the html. so anything in the html is search engine friendly. links that use text rather than images are always better! NB if your page is called www.example.com/page.php?id=123 google will only look at www.example.com/page.php (i think), and not look at the page as a whole ?id=123, or consider it a separate page. This means two things: (1) submit them a SITEMAP. this is really important in terms of SEO. google have loads of info on making a sitemap.xml (you can just copy their example and modify it), and (2) make sure that page.php has something on it, a "default" content, e.g. in your if stmt, do "if (it's a charity) { put this text } elseif (it's something else) { do this } else { (do this) } Make sure you have an "else" and not just all "elseifs", that way page.php will always have some content for search engines that can't see your page.php?id=123 good luck! Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/#findComment-261471 Share on other sites More sharing options...
448191 Posted May 25, 2007 Share Posted May 25, 2007 Without trying to complicate things for a n00b, may I suggest using a basic XML file to store optional content. May seem overkill now (I don't think so, but one could), but it will make your life easier when you decide you need a CMS. $dom = new DOMDocument; $dom->load('file.xml'); $fragment = $dom->getElementById($_GET['purpose'].'greetingcards'); $fragment->removeAttribute('xml:id'); echo $fragment; <content> <div xml:id="officegreetingcards"> <div id="h1"> Office greeting cards</div> <div id="blurb">Are you the person who has to pop out and buy all the greeting cards for people at work? Are you paying £2 a pop? Crazy, isn’t it? </br></br> On this site, you can buy individual greeting cards for £1.20 each, packs of 5 mixed cards for £1 per card, or packs of 25 same-design cards for 50p per card. Click on a design you like, and the options - including mixed packs - will pop up, as if by magic!</br></br>If you know you would like only Birthday, or Get Well cards, please use the Message dropdown to your left. </div> <div> <div xml:id="hotelgreetingcards"> <div id="h1"> Hotel greeting cards</div> <div id="blurb">Our greeting cards are used in several prestigious hotels within the UK. </br></br> Greeting cards may be given to guests to welcome them, or to help celebrate a guest’s birthday or anniversary. Prices start from just 50p. Please click on a design you like to display the packaging options and prices. If you would like to narrow down the results, please use the dropdowns to your left. </div> </div> <div xml:id="greetingcards"> <div id="h1"> Greeting cards</div> <div id="blurb">We stock over 80 designs of greeting cards, all photographic, all square, and all available to you as a consumer from 50p, or as a retailer from 65p (individually wrapped in cellophane). Click on any of the images to see whether the card is available blank or messaged, and to see what the pricing options are. </div> </div> </content> Naturally you don't actually use $_GET that way. And you'll have to be a little smarter in grouping and loading content when you get more content (because the whole file is loaded in memory using DOM). Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/#findComment-261506 Share on other sites More sharing options...
tripleaaa Posted May 25, 2007 Author Share Posted May 25, 2007 Thanks marmite and 448191. Ok I tried the code marmite posted and that works fine. Now with XML I'm really lost. 1. Do I create a file with a php ending with: <?php $dom = new DOMDocument; $dom->load('file.xml'); $fragment = $dom->getElementById($_GET['purpose'].'greetingcards'); $fragment->removeAttribute('xml:id'); echo $fragment; ?> 2. Then create a file with the content for XML with an ending file name of file.xml? Sorry for all the questions. Thank you again for your help Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/#findComment-261542 Share on other sites More sharing options...
448191 Posted May 25, 2007 Share Posted May 25, 2007 You know what; it's at this point probably easier to forget about XML and use simple filename based includes instead. i.e.: <?php ini_set('open_basedir', '/home/blah/devroot'); ini_set('include_path', get_include_path().DIRECTORY_SEPARATOR.'/home/blah/devroot/html'); ?> <html> ... <?php if(isset($_GET['page']) && !empty($_GET['page'])){ $file = 'content/'.$_GET['page'].'.php'; if(file_exists($file)){ include $file; } else { include 'error/404.php'; } } else { include 'content/default.php'; } ?> The benefit to this over using echo's is that you can have someone edit the HTML without having to know (possibly screwing up) php. Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/#findComment-261553 Share on other sites More sharing options...
tripleaaa Posted May 25, 2007 Author Share Posted May 25, 2007 448191, Thank you for your help I will try this to. I guess I should start reading up on XML. tks hv a great weekend Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/#findComment-261557 Share on other sites More sharing options...
448191 Posted May 25, 2007 Share Posted May 25, 2007 Forget about XML for now. You won't need it any time soon. Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/#findComment-261561 Share on other sites More sharing options...
Wildbug Posted May 25, 2007 Share Posted May 25, 2007 Another interesting idea would be to use a script without an extension, sort of like Wikipedia does. So instead of http://en.wikipedia.org/wiki.php?topic=PHP you use http://en.wikipedia.org/wiki/PHP, and the script takes "/PHP" as an argument like a query string, but it looks like it's part of the filesystem. It's needlessly more complex than using a query string, but the URLs look nicer. If you're interested in using this method, see some of the user comments under Hiding PHP in the docs. Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/#findComment-261600 Share on other sites More sharing options...
tripleaaa Posted May 26, 2007 Author Share Posted May 26, 2007 Wildbug, tks for the tip and will try this as well. Quote Link to comment https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/#findComment-262246 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.