RE: [PHP] Parsing database variables
- From: linux@xxxxxxxxxxxxxxxxx ("Jake McHenry")
- Date: Sat, 31 Mar 2007 11:39:36 -0400
Yep, that's what I did last night right after I sent the email out... All is
working good now.. THANKS!
Jake
-----Original Message-----
From: Jim Lucas [mailto:lists@xxxxxxxxx]
Sent: Saturday, March 31, 2007 4:15 AM
To: Jake McHenry
Cc: php-general@xxxxxxxxxxxxx
Subject: Re: [PHP] Parsing database variables
Jake McHenry wrote:
Ok, this is working good, except for one problem... I have variableand then it never
$pay_rate and $pay_rate_bap ... It finds $pay_rate first
finds $pay_rate_bap because it changes it to say..21_bap... Anyone know of
anything else that may work? I have been messing aroundwith eval, and I
havn't gotten it to work even once yet... Always comes backwith error at
line 5 of eval'd.... And line 5 of the paragraph is a blankline... Line 4
is plain text... Not even a variable until line 12...
Fine, just switch the order you are adding them to the two
different arrays.
instead of this:
$find[] = '$pay_rate';
$find[] = '$pay_rate_bap';
$replace[] = $pay_rate;
$replace[] = $pay_rate_bap;
do this
$find[] = '$pay_rate_bap';
$find[] = '$pay_rate';
$replace[] = $pay_rate_bap;
$replace[] = $pay_rate;
find the longer one first
thinking I will
I guess next I will play around with preg_replace, but I'm
have the same problem as I did with str_replace... As longas the variable
names have any kind of similar names.... Correct? I canresolve this I
suppose, but the data is already in place and trying towork around it...
Thanks,
Jake
-----Original Message-----
From: Jim Lucas [mailto:lists@xxxxxxxxx]
Sent: Friday, March 30, 2007 7:32 PM
To: Jake McHenry
Cc: php-general@xxxxxxxxxxxxx
Subject: Re: [PHP] Parsing database variables
Jake McHenry wrote:
Hi everyone,hour without
I have been searching and trying to do this for the past
success yet....there a way for
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
me to get the output from mysql_query to use the currentscript variables in
place of the same variable name within the database output?If I read the manual correct about how to setup the input
Thanks,
Jake
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.23/740 - Release
Date: 3/30/2007 1:15 PM
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.23/740 - Release
Date: 3/30/2007 1:15 PM
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.23/740 - Release Date: 3/30/2007
1:15 PM
.
- References:
- Re: [PHP] Parsing database variables
- From: Jim Lucas
- Re: [PHP] Parsing database variables
- Prev by Date: Re: [PHP] Saving css state in javascript and passing to php via form submit
- Next by Date: programs taking too long to exit
- Previous by thread: Re: [PHP] Parsing database variables
- Next by thread: RE: [PHP] Parsing database variables
- Index(es):