variables from mysql to echo page variable value on page

Discussion in 'PHP' started by ched, Jun 12, 2009.

  1. #1
    Hi everyone, I have a problem that is making me pull my hair out.

    Here goes:
    I have the following text in a mysql field $City is in the County of $County
    and within my php page I have $City = "Liverpool" $County = "Merseyside"

    What I want to happen is when the mysql field is echoed within the page it shows
    Liverpool is in the County of Merseyside
    but it actually shows
    $City is in the County of $County

    Any idea how I get the mysql variables to use the page variable values?

    I hope that makes sense as it is driving me nuts.

    Please help.......
     
    ched, Jun 12, 2009 IP
  2. brian65

    brian65 Active Member

    Messages:
    1,172
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    88
    #2
    How about something like:

    echo $City . " is in the county of " . $County;

    or:

    <p><?=$City?> is in the county of <?=$County?></p>
     
    brian65, Jun 12, 2009 IP
  3. ched

    ched Active Member

    Messages:
    185
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #3
    Cheers for the reply. The first wont work as the whole phrase $City is in the County of $County is in the mysql field.

    I tried the second and unfortunately that didnt work either. :(

    Thanks very much for trying
     
    ched, Jun 12, 2009 IP
  4. HorseGalleria

    HorseGalleria Peon

    Messages:
    91
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $your_mysql_string = ' $City is in the County of $County';

    $your_mysql_string = str_replace(array('$City','$County'),array($City,$County),$your_mysql_string);
    echo $your_mysql_string;
    
    Code (php):
     
    HorseGalleria, Jun 12, 2009 IP
    ched likes this.
  5. ched

    ched Active Member

    Messages:
    185
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #5
    I will have a go.

    Thanks very much. I will report back.
     
    ched, Jun 12, 2009 IP
  6. ched

    ched Active Member

    Messages:
    185
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #6
    Had a little play and had to edit code a little so now its

    $your_mysql_string = str_replace(array("\$City","\$County"),array($City,$County),$your_mysql_string);
    echo $your_mysql_string;
    
    Code (php):
    And that works!!!! Thanks very Very much. I am now going to watch TV and have a cool beer.
    Thanks.
     
    ched, Jun 12, 2009 IP