Xajel Posted March 8, 2008 Share Posted March 8, 2008 I have a small table for word translating, the table includes category ( wich specify in wich category this pharse is used, duo to some dublicates in name ), the pharse name, and translation in both Arabic & English. so the coulmns are id, category, name, ar, en the problem I have is I use this fuction too much, and it will take too many queries if I choosed to make a query every time I needed a single word only !! that's why I'm planning to load the whole table into multi-dimentional array then I'll just put the array as I want for example // example $trans["category"]["name"]["ar"] // for arabic translation... $trans["category"]["name"]["en"] // for english translation... // real example $trans["hw"]["cpu"]["ar"] // open's Hardware category, the pharse is 'cpu', and the lang is Arabic $trans["sw"]["os"]["en"] // open's Software category, the pharse is 'os' and the lang is English the proble is with loading the table into this multidimentional array, I may use some while and if or something like that, I'm currently working on one, but I want some ideas or maybe just another effective way of doing this... just to note, - categories may not be in order in the db and they don't have specific number, they maybe 5 or 10. - pharses are not fixed in number, some categories may have only two pharses, and some other may have 14 pharses or more. - currenly only two languages, Arabic and English, but in not the near future we may have more. the array will be filled one time only ( per page or per the whole script or per session, I don't know how PHP is handling variables and arrays ), so only one query will be required rather than a query for every pharse ! Quote Link to comment Share on other sites More sharing options...
Barand Posted March 8, 2008 Share Posted March 8, 2008 <?php function getTransArray() { $sql = "SELECT category, name, language, phrase FROM translationTable ORDER BY category, name, language"; $res = mysql_query($sql) or die (mysql_error()); $trans = array(); while (list ($cat, $name, $lang, $phr) = mtsql_fetch_row($res)) { $trans[$cat][$name][$lang] = $phr; } return $trans; } ?> Quote Link to comment Share on other sites More sharing options...
Xajel Posted March 8, 2008 Author Share Posted March 8, 2008 Thanks Barand, ofcourse after some changes the original table has both Arabic & English translation in the same row, and there's no Pharse column so I changed the code to if (!is_array($trans)) { //function getTransArray() { $sql = "SELECT `category`, `name`, `ar`, `en` FROM `translate` ORDER BY category, name"; $res = mysql_query($sql) or die (mysql_error()); $trans = array(); while (list ($cat, $name, $ar, $en) = mysql_fetch_row($res)) { $trans[$cat][$name]["ar"] = $ar; $trans[$cat][$name]["en"] = $en; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.