Page 1 of 1

Is It Possible to Include only certain variables from a php

Posted: Sun Jun 18, 2006 5:16 pm
by gaillg
Is it possible to include only a certain group of variables when trying to include variables from another file?

I currently maintain a website for a realtor.

I use a txt file to include all variables for each listing like the following

$price="what ever the price is";
$bedrooms="number of bedrooms";
etc.

I include the txt file into the listing.php I have setup and that creates the page for each lising.

I would like to find a way for the featured homes page (a page that has a small amount of information about each home and a link to the full details (listing.php)

I have tried just including the text file for each listing just befor that listings entry on the featured homes page, and that works. However the text file for each listing contains over 100 variables, I only need to use about 6 of those for each listing on featured homes page. If I include the full text file of every listing on the featured homes page (with more than 60 listings featured on it) the page then loads slower than I think it should.

So what I am asking is :

Is it possible to include only certain information (variables etc) without including the full file?

Posted: Sun Jun 18, 2006 6:07 pm
by printf
Sure it's possible, but how to do it best depends on your script. You can use a simple if() blocks/conditionals and enclose variable values, so they only get loaded when a condition has been triggered.


Code: Select all

if ( $type == 1 && $type == 2 )
{
	$price    = 'what ever the price is'; 
	$bedrooms = 'number of bedrooms'; 
}

if ( $type == 1 )
{
	$pool = 'has a pool, nice'; 
}
else if ( $type == 2 )
{
	$neighbor = 'not very nice, ouch!'; 
}

pif!

Posted: Sun Jun 18, 2006 6:08 pm
by tecktalkcm0391
No, I would suggest converting over to a MySQL Database, as then you could only pull the information you want from each record, when you want it. I know it would be a lot to convert, but if you google txt to MySQL Database, i'm sure you'll find something to do it for you.