[thelist] PHP: How to include a variable in DB text?

m u i n a r msk at muinar.com
Fri Jul 4 07:15:07 CDT 2003


A PHP script retrieves a text from the MySQL database. What I want
to accomplish is that I can include a variable in the text, i. e.
type it into the DB form, say

Lorem ipsum dolor sit $var   --->  submit  --->
$text = "Lorem ipsum dolor sit $foo";

... and retrieve the text from the DB so that $foo is being
filled in with its value:

$foo = "amet";
print( "$text" );   --->  Lorem ipsum dolor sit amet

Can this be achieved by inserting the variable with the right syntax into
the DB form ? I tried $foo, <?=$foo?>, etc. to no avail. Or is it a
a question of search-and-replace when fetching the text from the DB?
So that it replaces $ and the following characters by foo? Argh...

The code to retrieve the text so far is:

$query = "select * from moo_home where cat='$cat'";
$result = mysql_query( $query );
$myrow = mysql_fetch_array( $result );
$text = nl2br( stripslashes( $myrow[ "text$lang" ] ) );
echo $text;

($lang is one of the 3 languages of this site)

Thanks a lot   :)


_____  mike s. krischker  muinar internet studios
        ch-4058 basel  http://webdesign-schweiz.ch/
         erfolgreiche websites für unternehmen

 > > >  jetzt abonnieren:
        news und tipps für unternehmer im internet

More information about the thelist mailing list