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
Share on other sites

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

Link to comment
Share on other sites

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
Share on other sites

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


?>

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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