Jump to content
php.lv forumi

Koda optimizācija


m8t

Recommended Posts

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;
}

Link to comment
Share on other sites

        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;
       }

Link to comment
Share on other sites

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");
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...