Jump to content

Need help modifying my code


vmalli

Recommended Posts

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

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 :D, now I just need help with the fetching and all that

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!!

Thank you, a lot  ;D

 

 

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);


?>

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 =[

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....

 

 

 

ok, its almost working  ;D ;D ;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"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.