Jump to content


Photo

Using variable info into other page.


  • Please log in to reply
7 replies to this topic

#1 smartguyin

smartguyin
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts

Posted 02 March 2006 - 07:05 PM

I have set a variable as below

$title = "My Product Title"

I have created this variable in index.php and i wanted to use it in product.php how can i transfer from index.php to product.php soo that i can directly use it in all the product pages... like in title tag <title>[title]</title>

Please give me your suggestions.

Thanks in Advance
One of my php project >> http://www.mumbaipropertysite.com

#2 budeboy

budeboy
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 02 March 2006 - 07:35 PM

You could do it using sessions but if the variable is set in index.php they would have to have been on index.php for it to work on the other pages.

I think the best way would be to set it in an external file then calling that file on the pages you want the variable to be used on.

e.g. the code in the file would be
$title = "This is the title";

and the code you would use to call it would be (assuming the file was called title.inc)
include("title.inc");

hope that helps

#3 smartguyin

smartguyin
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts

Posted 03 March 2006 - 05:48 PM

No in the above example you showed me to prepare a separate file title.inc NO i don't want to use this.

I want the index.php send the variable directly to product.php soo that the variable content in index.php and used in product.php directly.

One of my php project >> http://www.mumbaipropertysite.com

#4 smartguyin

smartguyin
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts

Posted 04 March 2006 - 03:52 AM

Please Help ! I know many people have used such thing please guys i need your help !
One of my php project >> http://www.mumbaipropertysite.com

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 04 March 2006 - 04:19 AM

How are your users getting from index.php to product.php?

A form? A link?

You can always uses sessions. In index.php
<?php
session_start();
$some_variable = "Testing 123";
$_SESSION['some_variable'] = $some_variable;
?>
In product.php:
<?php
session_start();
$some_varible=$_SESSION['some_variable'];
?>

Ken

#6 smartguyin

smartguyin
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts

Posted 04 March 2006 - 04:35 AM

I'll give another example too get it more simplify.

Suppose there are 2 files product.php and header.php

header.php contains the meta tag and heading html code which is most common in all the product pages.

product.php contains the other part with all the content. >> There is a heading used in this page using this $product

Now I want to use the $product info in my header.php in title tag soo that the heading can be displayed in title tag.

I Hope the things must be clear now..

Thanks in Advance !
One of my php project >> http://www.mumbaipropertysite.com

#7 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 04 March 2006 - 04:54 AM

No, it's still clear as mud. Do you have any code you can post? Indicate what you want where...

Ken

#8 dayo

dayo
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 12 October 2006 - 06:47 PM

How are your users getting from index.php to product.php?
A form? A link?
You can always uses sessions. In index.php

<?php
session_start();
$some_variable = "Testing 123";
$_SESSION['some_variable'] = $some_variable;
?>
In product.php:
<?php
session_start();
$some_varible=$_SESSION['some_variable'];
?>
Ken



New here but desperately going through old files.  I probably should post here as i had put this somewhere else but this is relevant to my quest so I hope I am forgiven.

I am tying to modify some files that have the following simplified structure
<?php
include 'a.inc';
include 'b.inc';
?>

a.inc has the following struture
<?php
"A form for user input"
include 'A1.inc';
include 'A2.inc';
?>

A1.inc has the following struture
<?php
function 1 {
$x = "Value from user input form"
}
?>

A2.inc has the following struture
<?php
function 2 {
$y = $x + 1
}
include 'A2_1.inc';
?>

A2_1.inc has the following struture
<table>
<tr>
<td>"The value of $y"</td>
</tr>
</table>

The files are a bit more complicated than this (Gallery2 photo display software) but this is the basic structure.  I am struggling to get "The value of $y". 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users