Results 1 to 5 of 5

Thread: Insert $variable into?

  1. #1
    Join Date
    Feb 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Insert $variable into?

    I'm trying to insert a $varable into code to retrieve data from mysql.

    PHP Code:
       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.
    HTML Code:
    <h3 class="members">Members near  <?php echo $location;?></h3>
    But I'm unable to make a query with this.
    HTML Code:
    <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.
    HTML Code:
    {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.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    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):

    PHP Code:
    {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:

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

  3. #3
    Join Date
    Feb 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Schmoopy View Post
    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):

    PHP Code:
    {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.


    PHP Code:
    {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.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •