vmalli Posted March 3, 2008 Share Posted March 3, 2008 I have <?php $Main__page = array ( 'default' => 'include/default.txt', 'more' => 'include/more.txt', 'Error' => 'include/error.txt', ); if (isset($_GET['page']) && isset($Main__page[$_GET['page']])) { include($Main__page[$_GET['page']]); } else { include($Main__page['Error']); } ?> On my website to include pages dynamically. Everything works fine, but I what I want to do is put $Main__page = array ( 'default' => 'include/default.txt', 'more' => 'include/more.txt', 'Error' => 'include/error.txt', ); Into a database, and then have php print it back from the database. How can I do this, if it is possible? ??? Link to comment https://forums.phpfreaks.com/topic/94119-need-help-modifying-my-code/ Share on other sites More sharing options...
priti Posted March 3, 2008 Share Posted March 3, 2008 create a table page_details title link default include/default.txt more include/more.txt store like this then make queries to fetch according to $_GET['page'] from db. Regards Link to comment https://forums.phpfreaks.com/topic/94119-need-help-modifying-my-code/#findComment-482192 Share on other sites More sharing options...
vmalli Posted March 3, 2008 Author Share Posted March 3, 2008 ok, i've got the database all setup in phpmyadmin, but I cant figure out how to use the fetch to include the correct file. Could someone please show me an example code. Thanks, again Link to comment https://forums.phpfreaks.com/topic/94119-need-help-modifying-my-code/#findComment-482262 Share on other sites More sharing options...
vmalli Posted March 3, 2008 Author Share Posted March 3, 2008 I just retrieved this query string from phpmyadmin, so I guess this will be needed somewhere in the code $sql = 'SELECT * FROM `Main__page` LIMIT 0, 30 '; also, I have figured out how to connect to my database , now I just need help with the fetching and all that Link to comment https://forums.phpfreaks.com/topic/94119-need-help-modifying-my-code/#findComment-482271 Share on other sites More sharing options...
priti Posted March 3, 2008 Share Posted March 3, 2008 simple fetch the data from database based on the page i.e url?page=default $page=$_GET['page']; //now query your table with this something like select include_link from tabl_name where page="$page" then you can use include_link as you are doing in the coding.Make it more robust i have just outline what needs to be done in order to achieve your goal. happy coding!! Link to comment https://forums.phpfreaks.com/topic/94119-need-help-modifying-my-code/#findComment-482277 Share on other sites More sharing options...
vmalli Posted March 4, 2008 Author Share Posted March 4, 2008 Thank you, a lot But I am a rookie at PHP. I tried playing around with the things you gave me but just cant get it working I will give you some more info so you have a better idea of what to tell me My Test page test.php: <?php $Main__dbhost = 'localhost'; $Main__dbuser = 'USER'; $Main__dbpass = 'PASS'; $Main__dbconnect = mysql_connect($Main__dbhost, $Main__dbuser, $Main__dbpass) or die (mysql_error()); $Main__dbname = 'MainSN'; mysql_select_db($Main__dbname); ?> <?php $page = $_GET['page']; mysql_query ("SELECT * FROM `Main__title` WHERE Name = '$title'") or die (mysql_error()); ?> <?php mysql_close($Main__dbconnect); ?> Link to comment https://forums.phpfreaks.com/topic/94119-need-help-modifying-my-code/#findComment-482450 Share on other sites More sharing options...
ohdang888 Posted March 4, 2008 Share Posted March 4, 2008 is this something you will be calling on a number of pages, and you want to be able to change 1 file when you make a change rather than lots? then just use php inlcude <?php include("file.php");?> Link to comment https://forums.phpfreaks.com/topic/94119-need-help-modifying-my-code/#findComment-482455 Share on other sites More sharing options...
vmalli Posted March 4, 2008 Author Share Posted March 4, 2008 Its a dynamic page(?page=blah). Right now I am using the page alias => pagefile as an array in the document. All I want to do is use that array from the database priti is already helping me, I know what he is trying to say, but I just dont know enought to create the code =[ Link to comment https://forums.phpfreaks.com/topic/94119-need-help-modifying-my-code/#findComment-482460 Share on other sites More sharing options...
priti Posted March 4, 2008 Share Posted March 4, 2008 dear i am gal :-) Next $page = $_GET['page']; mysql_query ("SELECT * FROM `Main__title` WHERE Name = '$title'") or die (mysql_error()); query if correct but where is the more part you need to do $result=mysql_query(query); //it return the resultset resource type $row=mysql_fetch_row($result); //return array // you can do print_r($row) to check what result you got now $page=$row[0]; //you need to check your index now you are ready with your page to include hope it help you to sail further.... Link to comment https://forums.phpfreaks.com/topic/94119-need-help-modifying-my-code/#findComment-482578 Share on other sites More sharing options...
vmalli Posted March 4, 2008 Author Share Posted March 4, 2008 Sorry for misunderstanding Miss Link to comment https://forums.phpfreaks.com/topic/94119-need-help-modifying-my-code/#findComment-482590 Share on other sites More sharing options...
vmalli Posted March 4, 2008 Author Share Posted March 4, 2008 ok, its almost working ;D <?php $page = $_GET['page']; $query="SELECT * FROM `Main__title` WHERE Name = '$page'"; // query if correct but where is the more part you need to do $result=mysql_query($query); //it return the resultset resource type $row=mysql_fetch_row($result); //return array // you can do print_r($row) to check what result you got $page=$row[0]; //you need to check your index // print_r($row); if (isset($_GET['page']) && isset($row[1][$_GET['page']])) { echo($row[1][$_GET['page']]); } else { echo "The specified page could not be found."; } ?> But when I type text.php?page=default all I get is "H". It should say "Home Page" Link to comment https://forums.phpfreaks.com/topic/94119-need-help-modifying-my-code/#findComment-482597 Share on other sites More sharing options...
vmalli Posted March 4, 2008 Author Share Posted March 4, 2008 Nevermind I fixed it!!!!!!!!!!!!!!!!!!!!!!!! THANK YOU VERY VERY VERY VERY VERY MUCH!!! YOU MADE MY DAY HAPPY ;D WOOHOO! Link to comment https://forums.phpfreaks.com/topic/94119-need-help-modifying-my-code/#findComment-482605 Share on other sites More sharing options...
priti Posted March 4, 2008 Share Posted March 4, 2008 hey thats great !!! glad to help you Link to comment https://forums.phpfreaks.com/topic/94119-need-help-modifying-my-code/#findComment-482656 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.