开发者

populate multi-dimensional arrays

开发者 https://www.devze.com 2022-12-18 23:21 出处:网络
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 mys

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 numbe开发者_运维百科r
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


$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.

0

精彩评论

暂无评论...
验证码 换一张
取 消