Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-02-2006, 08:47 PM   PM User | #1
AntoMUFC
New Coder

 
Join Date: Aug 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
AntoMUFC is an unknown quantity at this point
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 08:49 PM..
AntoMUFC is offline   Reply With Quote
Old 01-02-2006, 09:05 PM   PM User | #2
Velox Letum
Senior Coder

 
Join Date: Apr 2005
Location: Colorado, United States
Posts: 1,208
Thanks: 0
Thanked 0 Times in 0 Posts
Velox Letum is an unknown quantity at this point
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();"
Velox Letum is offline   Reply With Quote
Old 01-02-2006, 09:07 PM   PM User | #3
Element
Regular Coder

 
Element's Avatar
 
Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 855
Thanks: 2
Thanked 2 Times in 2 Posts
Element is an unknown quantity at this point
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 09:12 PM..
Element is offline   Reply With Quote
Old 01-02-2006, 09:19 PM   PM User | #4
Velox Letum
Senior Coder

 
Join Date: Apr 2005
Location: Colorado, United States
Posts: 1,208
Thanks: 0
Thanked 0 Times in 0 Posts
Velox Letum is an unknown quantity at this point
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();"
Velox Letum is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:39 AM.


Advertisement
Log in to turn off these ads.