Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Insert value from another page?
Old 12-10-2009, 08:21 PM Insert value from another page?
Average Talker

Posts: 24
Trades: 0
Hi. Guys

I need some help from anybody here... maybe my ask so look easy for you..

Code:
this page named parameter.php <? 
//the value of page1.php
$config["title"] = "Ok go now"; 
$config["color"] = "red"; 
$config["pages"] = "two"; 
$config["theme"] = "ocean"; 
$config["lang"] = "eng"; 
$config["charset"] = "ISO-8859-1"; 
etc (more..)

//the value of page2.php :
$config["title"] = "Stay here!"; 
$config["color"] = "blue"; 
$config["pages"] = "two"; 
$config["theme"] = "ocean"; 
$config["lang"] = "it"; 
$config["charset"] = "UTF-8"; 
//etc (more..) 

//the value of page3.php also many same with above:
$bla-bla = "bla-bla";
?>

I want to collect the form parameter.php above to page1.php, also page2.php up to page1001.php
with each page:
Code:
page1.php
<?
<html>
<head>
<title><?=$config["title"];?></title>
bla..bla..<?=$config["color"];?> ....<?=charset;?>
//all value of page1.php must be store here
?>

page2.php
<?
<html>
<head>
<title><?=$config["title"];?></title>
bla..bla..<?=$config["color"];?> ....<?=charset;?>
//all value of page2.php must be store here
?>
up to page1001.php
so on in config.php
<?
if (!isset($config["theme"]) or empty($config["theme"]) or !is_file("./themes/".$config["theme"].".php")) {
    $config["theme"] = ""; // default
    }
    include("themes/" .$config["theme"]. ".php"); ?>
now my problem is how to insert all value each page from parameter.php?

Last edited by jones; 12-10-2009 at 08:22 PM..
jones is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-11-2009, 12:11 AM Re: Insert value from another page?
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Ehm, ok. Make the $config variable an array, so each page has it's own values. Then include the page where the variable is created.

PHP Code:
<?php
// this is config.php
$config = array(
=> array(
      
'title' => 'value',
      
'color' => 'value',
      ...
   ),
=> array(
      
'title' => 'value',
      
'color' => 'value',
      ...
   ),
=> array(
      
'title' => 'value',
      
'color' => 'value',
      ...
   ),
...
);
?>
PHP Code:
<?php
require 'config.php';

// now you can use the array as in
echo $config[$page]['title'];
// where $page is a number 0-1000
?>
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 12-11-2009, 01:39 AM Re: Insert value from another page?
Average Talker

Posts: 24
Trades: 0
Hi lizciz, nice to meet you again...
firstly i appreciate your input and say thankyou..
secondly... I found another way...

Code:
<?
//PHP Code:

$config["title"] = "Ok go now";
$config["color"] = "red";
$config["pages"] = "two";
$config["theme"] = "ocean";
$config["lang"] = "eng";
$config["charset"] = "ISO-8859-1";

$_Session['config1'] = $config;


//the value of page2.php :
$config["title"] = "Stay here!";
$config["color"] = "blue";
$config["pages"] = "two";
$config["theme"] = "ocean";
$config["lang"] = "it";
$config["charset"] = "UTF-8";
//etc (more..)
$_Session['config2'] = $config;
?>
<?php
require 'config.php';
echo $_Session['config1']['lang'];
?>
but which one most suitable for me..? and the last input without using array ... what the different?

Last edited by jones; 12-11-2009 at 01:40 AM..
jones is offline
Reply With Quote
View Public Profile
 
Old 12-11-2009, 07:35 AM Re: Insert value from another page?
Defies a Status

Posts: 1,606
Trades: 0
My PHP is all self taught but I don't think it makes a difference whether you use an array or simply assign values to variables in the config file as long as all the variable names are unique to the scripts where they will be used.

Quote:
$config["title"] = "Ok go now";
$config["color"] = "red";
$config["pages"] = "two";
$config["theme"] = "ocean";
$config["lang"] = "eng";
$config["charset"] = "ISO-8859-1";
Quote:
$title = "Ok go now";
$color = "red";
$pages = "two";
$theme" = "ocean";
$lang = "eng";
$charset = "ISO-8859-1";
Both of the above will yield the same result when invoked in another script if the config file is included. The syntax is different when you use them.
Quote:
echo $config["color"] ;
ech $color ;
There is almost always more than one way to do something.

Do note that bolded part above $config["title"] and $title could be used on the same page as different valid variables.
__________________
Colbyt

Please login or register to view this content. Registration is FREE
colbyt is offline
Reply With Quote
View Public Profile
 
Old 12-11-2009, 11:05 AM Re: Insert value from another page?
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
If I'd do something like this I'd make use of a database. Have a table with the fields 'pageNbr', 'title', 'color' etc. and add a row for each of your 1000 pages. Then instead of including a file with a huge array you just fetch one row and use those variables. If you're new to databases I recommend tizag.com's tutorial.

About your solution with sessions. Well, I can't technically proove this but it "feels" as if using sessions would be less efficient and very unnecessary. That would make them accessible through the whole session, so it would take up more memory for a longer time, or something like that :P
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 12-12-2009, 06:48 PM Re: Insert value from another page?
Average Talker

Posts: 24
Trades: 0
Hi lizciz you gave me good advice always, thankyou..

you right, that indeed efficient if i using database for config page that we talk before.. but i litle idiot with database and also from beginning one all setup and code using flat file as datastore, so if i change the concept to use database that maybe need recode at all.

but your advice that i need for next time.
jones is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Insert value from another page?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.55067 seconds with 12 queries