Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Print Variable From Database

    Hi all,

    i have a sql database and i want to add 100% customisable phrases to my product.

    but now n then there needs to be a variable

    e.g. atm i have:

    print "Welcome To $sitename's Support Helpdesk";

    this displays:
    Welcome To FLCup's Support Helpdesk

    now, to make that customisable i would need

    print "$phrase[headertext]"; // of corse i'll have a sql query i aint that dumb.

    so to the sql database i go and insert "$sitename's Support Helpdesk" into a field on the phrases database.

    i refeshed my site and now it says
    $sitename's Support Helpdesk // obviously not taking $sitename as a variable but as text

    .: so what am i asking? :.

    i am askin if there is a way to have things like $sitename in a field in the database and a php script notice that and print it as a variable and not text.

    so that $phrase[headertext] prints: Welcome To FLCup's Support Helpdesk not Welcome To $sitename's Support Helpdesk

    any help would be great,

    thanks
    Anto

    p.s a 2nd example if needed:

    print "Welcome to $sitename's support center, choose an option below";
    prints: Welcome to SupportCenter's support center, choose an option below

    how can i have $phrase[welcome] not say
    Welcome to $sitename's support center, choose an option below
    Last edited by AntoMUFC; 01-02-2006 at 09:49 PM.

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Instead, you could insert [sitename]'s Support Helpdesk into the database, then...

    PHP Code:
    $sitename 'SupportCenter'// I suppose this would be set by a SQL query result.
    $phrase['headertext'] = str_replace('[sitename]'$sitename$phrase['headertext']);
    echo 
    $phrase['headertext']; // Prints 'SupportCenter's Support Helpdesk' (without quotes). 
    This is a relatively secure solution to this problem...using eval() would be a security nightmare.
    "$question = ( to() ) ? be() : ~be();"

  • #3
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    yes, when you insert the phrase, you need to escape the string, assuming it isn't showing up as the real site name becuase you use single quotes on the query, so you would need to do something like

    headertext = `Welcome to '.$sitename.'\'s HelpDesk!`

    or the same methed in the variable your using on headertext, if you are.

    And its best when you call the row to use: $phrase['headertext']

    Edit: Was writing mine while Velox already was apparently, but this is another solution, to add the name before you call it back, so the str_replace() wouldn't be nessessary if you use this.
    Last edited by Element; 01-02-2006 at 10:12 PM.

  • #4
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    However, if you did use Element's method, the phrase wouldn't be updated if you changed the name. If you want to go the DB method, my way would be a good way. Another way might to be to just make a large language file with all the phrases, that'd make it pretty easy.
    "$question = ( to() ) ? be() : ~be();"


  •  

    Posting Permissions

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