Log in

View Full Version : Insert $variable into?



LisaM
02-04-2010, 01:39 PM
I'm trying to insert a $varable into code to retrieve data from mysql.


include("./local/geoip/geoip.inc");
include("./local/geoip/geoipcity.inc");
include("./local/geoip/geoipregionvars.php");
$gi = geoip_open("./local/geoip/GeoLiteCity.dat", GEOIP_STANDARD);
$rsGeoData = geoip_record_by_addr($gi, $_SERVER ['REMOTE_ADDR']);
geoip_close($gi);
$location = $rsGeoData->region;
$location being the variable. I can echo $location onto the html page using this. Works ,no problem.

<h3 class="members">Members near <?php echo $location;?></h3>
But I'm unable to make a query with this.

<div class="block members">
{members:limit=10,profile_state=<?php=$location;?>,cache_time=0}
</div>
It would also help if I knew exactly what type of code/script this is.

{members:limit=10,profile_state= ******, cache_time=0}
The <div class="block members"> is after the "echo" so I know the $location is getting there, just appears to be a problem with the way it's interepted. And/or the {} brackets around the code. If I manually edit the file, remove <?php=$location;?> and substitue it with a state value, it works.
Any help here will most certainly be appreciated.

Schmoopy
02-04-2010, 06:14 PM
Not sure what that code is, but for the variable to be output you need to put it like this, without the php bit (it will cause a parse error):



{members:limit=10,profile_state=<?=$location?>,cache_time=0}

That's assuming that your server has short_open_tags turned on, which it may not do.

The most reliable way is to just echo it as normal:



{members:limit=10,profile_state=<?php echo $location; ?>,cache_time=0}

LisaM
02-04-2010, 06:49 PM
Not sure what that code is, but for the variable to be output you need to put it like this, without the php bit (it will cause a parse error):



{members:limit=10,profile_state=<?=$location?>,cache_time=0}

That's assuming that your server has short_open_tags turned on, which it may not do.
short_open-tags is enabled. And I've tried every conceivable combination possible.

The most reliable way is to just echo it as normal:

Reliable? How can it be reliable if it don't work?

Echoing it puts it on the page not in the database where it needs to go.




{members:limit=10,profile_state=<?php echo $location; ?>,cache_time=0}


Actually I don't think anybody here knows any more about this than I do.
Thanks anyway for your answer.

djr33
02-04-2010, 07:34 PM
I recently successfully set this up. I'm using the .dat files; how are you using the database? Is it mysql? I have not seen any documentation about "queries" with the .dat files. Instead, there is just a PHP class setup that easily does what you're looking for.
I don't understand what your file/system looks like. You just posted one line. My only guess is that you are FIRST parsing with something else, THEN parsing with PHP, which means that you are not finding a match for the TEXT of <?php echo $location; ?> because it is not yet parsed. Maybe you should change with language parses first?
Or, as I said, just approach it in a different way.
And first issue first: what Schmoopy said above is true: <?php=...?> is incorrect code. If you fix that (make it look like the other example in your first post), and it still doesn't work, then post more of the code and maybe a link to where you found the {.....} syntax.

traq
02-04-2010, 11:09 PM
First thing, no one knows how the {...} syntax is being used. Is it part of a CMS you're using (my best guess)? If so, which one? I believe something else is using this code, alongside or along with PHP, and that's where your issue lies.