views:

218

answers:

1

hello, im just working on integrating a script into my own site and this script (being that is has a chat feature) has inbuilt smilies, my site also has smilies but the url of them is stored in the sites mysql db, pulling said files from the db into the script im integrating is easy, but the script uses a 2 dimensional array for the smilies (shown below) and i am not sure how i can parse the msyql query output to put the smilies from my site into the array format the script needs.

my smilies table is laid out per this:

id - autogenerated id number
code - code used to display smilie (eg :) )
imgsrc - the image to replace above code with

the script uses the following for its smilies array:

    // Smileys
$smileys = array( 

':)'    =>  'smiley',
':-)'   =>  'smiley',
':('    =>  'smiley-sad',
':-('   =>  'smiley-sad',
':D'    =>  'smiley-lol',
';-)'   =>  'smiley-wink',
';)'    =>  'smiley-wink',
':o'    =>  'smiley-surprise',
':-o'   =>  'smiley-surprise',
'8-)'   =>  'smiley-cool',
'8)'    =>  'smiley-cool',
':|'    =>  'smiley-neutral',
':-|'   =>  'smiley-neutral',
":'("   =>  'smiley-cry',
":'-("  =>  'smiley-cry',
":p"    =>  'smiley-razz',
":-p"   =>  'smiley-razz',
":s"    =>  'smiley-confuse',
":-s"   =>  'smiley-confuse',
":x"    =>  'smiley-mad',
":-x"   =>  'smiley-mad',

);

left side is code and right is filename (script appends the extension and prepends location itself)

hopeing this isnt out of the realms of posibility.

cheers

+3  A: 
$result = mysql_query("SELECT Code, Filename FROM TABLE");
$smileys = array();
while($temp = mysql_fetch_assoc($result))
{
    $smileys[$temp['Code']] = $temp['Filename'];
}

The 'right side' is the key of the array, and we can dynamically assign them by putting a variable as the key.

Chacha102
well that seems to crash my site quite well, seems to lock up the page load at waiting for .....code im using : $result = mysql_query("SELECT scode, imgsrc FROM smilies");$smileys = array();while($temp = mysql_fetch_assoc){ $smileys[$temp['scode']] => $temp['imgsrc'];}table only has 1500 records so shouldnt take ages to load it surely
DJ_Steve
I mistakenly forgot to make `mysql_fetch_assoc` a function. That might have caused an infinite loop. Weird that it didn't cause an error.
Chacha102