Creating an array, within an array, with mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
azz0r_
Forum Commoner
Posts: 27
Joined: Mon Jan 24, 2005 4:15 pm

Creating an array, within an array, with mysql

Post by azz0r_ »

Basically Im going to put this function @ the top of the page and it will define the $swears array, I can then use this array to parse posts.

Anyway, the static part of the function works fine - however I am having trouble getting the database part to work!

Static

Code: Select all

$swears = array( 
	array('<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>', 'f*ck'), array('<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>', 'sh*t'), array('bitch', 'b*tch'), array('slut', 'sl*t'), array('wank', 'w*nk'), array('twat', 'tw*t'),
	array('cunt', 'c***'), array('bastard', 'bast*rd'), array('<span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span>', 'p*ss'), array('cock', 'chicken'), array('dick', 'd*ck'),array('whore', 'wh*re'));
but for the database part Ive tried everything but it just returns stuff like "Array ( [0] => [1] => ) "

The code

Code: Select all

$query = query("SELECT word, replacement FROM $unzDB.unz_swearbot");

	$swears = array();
	while ($row = mysql_fetch_array($query, MYSQL_ASSOC))
	&#123;$swears = array("$row->word", "$row->replacement");&#125;
Ideas?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

untested

Code: Select all

$inc = 0;
$swears = array(); 
while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) 
&#123;$swears&#1111;$inc++] = array("$row->word", "$row->replacement");&#125;
see if that does it!
azz0r_
Forum Commoner
Posts: 27
Joined: Mon Jan 24, 2005 4:15 pm

Post by azz0r_ »

Excellent, thank you!

Note for anyone who uses this code I shouldve had it as $row['word'] not $row->word ;)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

doesn't need the counter..

Code: Select all

$swears = array();
while($swears&#1111;] = mysql_fetch_assoc($query));
array_pop($swears);
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

god built many routes for his people to walk :wink:
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

Doesn't mean all routes lead to the divine.
azz0r_
Forum Commoner
Posts: 27
Joined: Mon Jan 24, 2005 4:15 pm

Post by azz0r_ »

So which is preferable?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

either is fine.
Post Reply