lukerodham Posted May 1, 2011 Share Posted May 1, 2011 hey guys how you all doing? ok im really looking for some help i've been playing with this code for quite some time now and still not got the hang of it. i'm currently trying to code a dynamic website as a portfolio for my designs and im trying to get to view the news.php file with an 'id' to view in the index file using an include() but for some reason its not happening very well. i keep getting the error message: Warning: include(inc/news.php?id=) [function.include]: failed to open stream: No error in C:\xampplite\htdocs\lukerodham\old\index.php on line 218 Warning: include() [function.include]: Failed opening 'inc/news.php?id=' for inclusion (include_path='.;C:\xampplite\php\PEAR') in C:\xampplite\htdocs\lukerodham\old\index.php on line 218 just wondering if anyone could shed any light on what i may have done wrong thanks guys ive left part of the code below if this will help. <?php $page = $_GET['page']; $news = $_GET['id']; if(!$page){ getnews(); } else { if($page = news){ include("inc/news.php?id=".$news); } else include("inc/".$page.".php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/235259-dynamic-page-help/ Share on other sites More sharing options...
wildteen88 Posted May 1, 2011 Share Posted May 1, 2011 You cannot pass a query string to a php include. Quote Link to comment https://forums.phpfreaks.com/topic/235259-dynamic-page-help/#findComment-1208967 Share on other sites More sharing options...
lukerodham Posted May 1, 2011 Author Share Posted May 1, 2011 ok thanks for the quick reply, i dont mean to sounds dumb but how else would i go about achieving what im looking for? Quote Link to comment https://forums.phpfreaks.com/topic/235259-dynamic-page-help/#findComment-1208970 Share on other sites More sharing options...
wildteen88 Posted May 1, 2011 Share Posted May 1, 2011 Just include news.php and don't pass a query string to. include("inc/news.php"); $_GET['id'] in news.php will return the id passed to it from your parent script (index.php?page=news&id=123) Before I said you can't pass a query string to an include. You can do this by using a url as the path include "http://site.com/file.php?var=value" However if you wish to use any variables from file.php within your parent script you wont be able to do this. This is because when you use a url as the path for an include only output from that file (text/html) will be returned. The raw php source code of that file will not be returned. Quote Link to comment https://forums.phpfreaks.com/topic/235259-dynamic-page-help/#findComment-1208973 Share on other sites More sharing options...
lukerodham Posted May 1, 2011 Author Share Posted May 1, 2011 ok thank you very much been a great help with only a few words Quote Link to comment https://forums.phpfreaks.com/topic/235259-dynamic-page-help/#findComment-1208975 Share on other sites More sharing options...
wildteen88 Posted May 1, 2011 Share Posted May 1, 2011 No problem. Also another tip. When comparing values you should be using the comparison operator (==), not the assignment operator (=). String should always be wrapped in quotes. Otherwise PHP will think the word news is a constant rather than a string. if($page = news){ So that line should read if($page == 'news'){ Quote Link to comment https://forums.phpfreaks.com/topic/235259-dynamic-page-help/#findComment-1208977 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.