Variables in a seperate file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Variables in a seperate file

Post by psurrena »

Is there a way that I can store variables in a separate file like an include?

When I put the following:

Code: Select all

$pcompany = $row['pcompany'];
$pfname   = $row['pfname'];
$plname   = $row['plname'];
$pstreet  = $row['pstreet'];
$pstreet2 = $row['pstreet2'];
$pcity    = $row['pcity'];
$pst      = $row['pst'];
$pzip     = $row['pzip'];
$pphone   = $row['pphone'];
$pfax     = $row['pfax']; 
$pcell    = $row['pcell'];
$pemail   = $row['pemail'];
$pweb     = $row['pweb'];
$pname	  = $pfname . ' ' . $plname;
in an include, it just prints what is above.

Here is a sample of the full code:

Code: Select all

<?php

	include 'includes/connect.php';
	
	$query = "SELECT * FROM personal";
	$result = mysql_query($query);
	mysql_query($query) or die (mysql_error());		
	while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
		
	include "includes/personal-var.php";
	
	}
?>
My reason for doing this is just to simplify my code.

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If there are no PHP tags around it, php won't know it's code.

Code: Select all

<?php

$pcompany = $row['pcompany'];
$pfname   = $row['pfname'];
$plname   = $row['plname'];
$pstreet  = $row['pstreet'];
$pstreet2 = $row['pstreet2'];
$pcity    = $row['pcity'];
$pst      = $row['pst'];
$pzip     = $row['pzip'];
$pphone   = $row['pphone'];
$pfax     = $row['pfax'];
$pcell    = $row['pcell'];
$pemail   = $row['pemail'];
$pweb     = $row['pweb'];
$pname    = $pfname . ' ' . $plname; 

?>
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post by psurrena »

Thanks
Post Reply