[thelist] php variables in mysql output

Eduardo Dominguez lalo_dominguez at yahoo.com
Wed Dec 6 09:04:31 CST 2000


Liz,
    I dont understand your problem very well, but php has something
called "variable variables" that you can use like:

<?php

    $data = "test";
    $var_var = "data";

    /* assign just use double $$ */
    $$var_var = $$var_var . " more text";

    /* in a string use ${} */
    echo "contents of \$data : <b>$data </b><br/>";
    echo "contents of \$\$var_var : <b>${$var_var} </b><br/>";
    echo "contents of \$var_var : <b>$var_var</b>";
?>

    would output "test"

    Hope this helps!

    If you need me to be more explicit, just say so :)

----- Original Message ----- 
From: "Liz Lawson" <lizlawson at charitycards.co.uk>
To: <thelist at lists.evolt.org>
Sent: Monday, December 04, 2000 8:15 AM
Subject: [thelist] php variables in mysql output


I want to hold some snippets of html in a mysql db (used to vary messages /
images depending on date rather than using hardcoded "if else else"), but I
need them to include PHP variable names. If I just echo out the result the
variable name is printed as a string ($foo is just "$foo").

  I can see two ways of doing this:

1. Instead of holding the html in the db and doing $topgraphic = stuff from
db, hold the names of include files which hold the actual html and use
something like $topgraphic = include($filenamefromdb). I don't like this
because of the possibility that a file specified in the db isn't there

2. use str_replace() or similar to replace the variable name in the string
with the variable value.

But I wondered if PHP already had the functionality for handling variables
in db output, and I just don't know how to use it.

thanks for any help

Liz

Liz Lawson
Web Designer, The Greetings Card Company Limited
www.charitycards.co.uk



---------------------------------------
For unsubscribe and other options, including
the Tip Harvester and archive of TheList go to:
http://lists.evolt.org Workers of the Web, evolt !


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com





More information about the thelist mailing list