Page 1 of 1

Variables in a seperate file

Posted: Fri Aug 18, 2006 12:33 am
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

Posted: Fri Aug 18, 2006 12:35 am
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; 

?>

Posted: Fri Aug 18, 2006 12:46 am
by psurrena
Thanks