[SOLVED]Select, Match and Pull from same row?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

[SOLVED]Select, Match and Pull from same row?

Post by blacksnday »

What I'm trying to do is convert my hard-coded preg_replace stuff
to be web-adminable, which means have the data stored in mySQL DB and
then using variables on php to pull.

The way i set it up for now is
Table= filter
Fields= word, replace

and the php would be

Code: Select all

$getWord = mysql_query("SELECT * FROM filter "); 
$checkWord = mysql_fetch_array($getWord);
$Word    = $checkWord['word'];
$Replace = $checkWord['replace'];
if ($Word  == $Word) {
	$html = preg_replace("#$Word#i", "$Replace", $html);
}else{
}
The problem with that is it will only replace the first word found.
How do I change it so it will replace anyword that matches whats in the DB?
Last edited by blacksnday on Fri Oct 28, 2005 5:31 am, edited 1 time in total.
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

Post by sebs »

try:

Code: Select all

while($checkWord = mysql_fetch_array($getWord))
{....}
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Post by blacksnday »

sebs wrote:try:

Code: Select all

while($checkWord = mysql_fetch_array($getWord))
{....}
doh!! lol....... its late(or early) and i havent slept in about 14 hours..

thanks for the obvious :D lol
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Post by blacksnday »

heh... the if else statement is useless also... i know
I just need some sleep 8O
Post Reply