m8t Posted May 22, 2010 Report Share Posted May 22, 2010 Vai ir kāds veids, kā optimizēt šo kodu? Varbūt ir kāda funkcija par kuru es nezinu un izdarītu šo visu manā vietā? function get_navigation() { $query = mysql_query("SELECT * FROM {$this->prefix}navigation WHERE nav_lang='{$this->language}' ORDER BY nav_sort ASC LIMIT 7"); while($row = mysql_fetch_array($query)) { $id = $row["nav_id"]; $out[$id]["nav_id"] = $id; $out[$id]["nav_sort"] = $row["nav_sort"]; $out[$id]["nav_name"] = $row["nav_name"]; $out[$id]["nav_linkto"] = $row["nav_linkto"]; } return $out; } Quote Link to comment Share on other sites More sharing options...
bubu Posted May 22, 2010 Report Share Posted May 22, 2010 function get_navigation() { $out = array(); $query = mysql_query("SELECT nav_id, nav_sort, nav_name, nav_linkto FROM {$this->prefix}navigation WHERE nav_lang='{$this->language}' ORDER BY nav_sort ASC LIMIT 7"); while($row = mysql_fetch_array($query)) { $out[$row["nav_id"]] = $row; } return $out; } Quote Link to comment Share on other sites More sharing options...
m8t Posted May 22, 2010 Author Report Share Posted May 22, 2010 Liels paldies! Tu tiko manu 88 rindiņu garo īso kodu pārvērti par 55 rindiņām garu īsu kodu. Vēl bija ideja salikt šo visu vienā funkcijā. Aptuveni šādi. function all($s, $s2) { $out = array(); $query = mysql_query($s, $s2); while($row = mysql_fetch_array($query)) { $out[$row[$s2]] = $row; } return $out; } function get_navigation() { return $this->all("SELECT..", "nav_id"); } Quote Link to comment Share on other sites More sharing options...
bubu Posted May 22, 2010 Report Share Posted May 22, 2010 Neaizmirsti pārbaudīt kļudu no mysql_query funkcijas: $query = mysql_query(...); if (!$query) { // kļūdas apstrāde vai: die(mysql_error()); } 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.