Is It Possible to Include only certain variables from a php

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
gaillg
Forum Newbie
Posts: 1
Joined: Sun Jun 18, 2006 5:04 pm

Is It Possible to Include only certain variables from a php

Post 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?
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post 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!
Last edited by printf on Sun Jun 18, 2006 6:08 pm, edited 1 time in total.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post 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.
Post Reply