Page 1 of 1

Creating an array, within an array, with mysql

Posted: Tue Feb 15, 2005 7:22 am
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?

Posted: Tue Feb 15, 2005 7:27 am
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!

Posted: Tue Feb 15, 2005 7:31 am
by azz0r_
Excellent, thank you!

Note for anyone who uses this code I shouldve had it as $row['word'] not $row->word ;)

Posted: Tue Feb 15, 2005 8:01 am
by feyd
doesn't need the counter..

Code: Select all

$swears = array();
while($swears&#1111;] = mysql_fetch_assoc($query));
array_pop($swears);

Posted: Tue Feb 15, 2005 8:05 am
by n00b Saibot
god built many routes for his people to walk :wink:

Posted: Tue Feb 15, 2005 1:33 pm
by protokol
Doesn't mean all routes lead to the divine.

Posted: Tue Feb 15, 2005 5:17 pm
by azz0r_
So which is preferable?

Posted: Tue Feb 15, 2005 5:26 pm
by feyd
either is fine.