Re: [PHP] Parsing database variables



Jake McHenry wrote:
Hi everyone,

I have been searching and trying to do this for the past hour without
success yet....



I have a database table with this in it:


<p>$name<p>
Period Ending Date: $ppe<p>
Etc.......


And in my script, these variables exist and have values. Is there a way for
me to get the output from mysql_query to use the current script variables in
place of the same variable name within the database output?



Thanks,
Jake


If I read the manual correct about how to setup the input values for str_replace()
you should be able to do the following.

This is completely untested, since I have now system like yours. But here is goes...


#setup the entries that you want to find.
$find[] = '$name';
$find[] = '$ppe';

#setup the values to be replaced.
#Mind you to keep the indexes the in sync with $find...
$replace[] = $name;
$replace[] = $ppe;

echo '<pre>';

while ( $row = mysql_fetch_assoc($resultHandle) ) {

$row = str_replace($find, $replace, $row);

// do something with $row. Display it maybe...

var_dump($row);

}

echo '</pre>';

Basically replace $find[0] with $replace[0] in any of the values of the return $row then replace the previous $row values with the newly modified values... Then go to the next index of $find[1] and $replace[1] and do the same thing until you are out of indexes.

But this is a much better way of doing this than using eval(). eval is an evil little function!



--
Enjoy,

Jim Lucas

Different eyes see different things. Different hearts beat on different strings. But there are times for you and me when all such things agree.

- Rush
.



Relevant Pages

  • Parsing database variables
    ... I have a database table with this in it: ... Period Ending Date: $ppe ... me to get the output from mysql_query to use the current script variables in ... place of the same variable name within the database output? ...
    (php.general)
  • Re: SetUp functions for multiple test cases
    ... couldn't find out how to implement a setup function, ... new database in-memory and fill it with example data for every single ... The True Unit Test Zealots will argue that all tests should be 100% ... SUnit from Smalltalk to Python: SUnit takes full advantage of ...
    (comp.lang.python)
  • [NEWS] Lawson Financials RDBMS Insecurity
    ... Beyond Security would like to welcome Tiscali World Online ... the database itself) to easily compromise the Lawson Financials' database. ... Setup #1 tends to be the preferred configuration method by Lawson ...
    (Securiteam)
  • Re: SetUp functions for multiple test cases
    ... couldn't find out how to implement a setup function, ... new database in-memory and fill it with example data for every single ... The True Unit Test Zealots will argue that all tests should be 100% ... should not interface with external resources like databases. ...
    (comp.lang.python)
  • Re: Word 2007
    ... I saved that database in each clients directory. ... forms setup to be merge documents. ... I had many choices setup for "if and if ...
    (microsoft.public.word.docmanagement)