Forum Moderators: coopster
I have got a variable that is set on the page ie $strBusiness = "some text";
$strTitle = "some text";
$strAddress = "some text";
Then i do a search to find different templates that are stored within a database. Once one is select it gets all the elements of the template and builds from the database.
The issue am having is calling the variable that has been set already within the while loop as the while gets the next part of the template
so the database will being back Business
So for the text that is already defined in $strBusiness I want this to be displayed
so am doing echo $str.$row['structure'];
but this just displays Business
Hope this make sense.
Cheers
Neil
Welcome to WebmasterWorld!
I think the two options you have are using an array rather than varibles or variable variables... Either way requires you to change your naming convention or your database.
Basically you need to 'match' something and what you are doing currently is echoing $str and $row['structure'].
You'll get exactly the same result with this:
echo $str;
echo $row['structure'];
I'm guessing the value of $row['structure'] is Business, so if you used a variable variable you could do it like this:
<?php
$row['structure']='Business';
$Business = "some text";
$Title = "some text";
$Address = "some text";
echo $$row['structure'];
?>
The other option I see is an array:
<?php
$row['structure']='Business';
$str['Business'] = "some text";
$str['Title'] = "some text";
$str['Address'] = "some text";
echo $str[$row['structure']];
?>
I'll let you decide which is best for your situation...