omarh2005 Posted August 23, 2007 Share Posted August 23, 2007 Hello for all what are the sepecification of the good code Quote Link to comment https://forums.phpfreaks.com/topic/66327-solved-the-specification-of-the-good-code/ Share on other sites More sharing options...
MadTechie Posted August 23, 2007 Share Posted August 23, 2007 erm.. really depends what the code is for? heres some Expandability Upgradeability Flexibility Useability but really we need a more detailed question and in the correct section (this isn't a PHP problem) Quote Link to comment https://forums.phpfreaks.com/topic/66327-solved-the-specification-of-the-good-code/#findComment-331811 Share on other sites More sharing options...
omarh2005 Posted August 23, 2007 Author Share Posted August 23, 2007 Which the best and faster from where the code ?! To write general add function usable in all websites(include many parameters), Or To write private add function usable in only a one website (less parameters) and in another website change it Quote Link to comment https://forums.phpfreaks.com/topic/66327-solved-the-specification-of-the-good-code/#findComment-331856 Share on other sites More sharing options...
MadTechie Posted August 23, 2007 Share Posted August 23, 2007 Use only the functions you need to per site but if a function seams to have "too many" parameters it should "probably" be setup as a class and/to be broken down into smaller functions. Quote Link to comment https://forums.phpfreaks.com/topic/66327-solved-the-specification-of-the-good-code/#findComment-331867 Share on other sites More sharing options...
omarh2005 Posted August 23, 2007 Author Share Posted August 23, 2007 what your openion with this function ?! function fun_add($tab,$id,$iman,$lenght,$error,$succ) { if ($id==0){//its insert function ! $res=("insert into $tab ()values()"); mysql_query($res); $id=mysql_insert_id(); }//end if // Get table Info $res1=mysql_query("desc $tab "); $c=0; while ($row1=mysql_fetch_array($res1)){ $c=$c+1; $fname[$c]= $row1[0]; } //2 to the first field acept id $q="update $tab set "; for ($i=0; $i<$lenght ; $i++) { $fi=$i+2; $q.="$fname[$fi]= '".$iman[$i]."' "; if($i!=$lenght-1) $q.=","; } $q.=" where id = '".$id."'"; //print $q; mysql_query($q) or die("not query"); if ( mysql_affected_rows()>0) { header("location:"."$succ"); exit; } else { header("location:"."$error"); exit; } } //$iman =array("hi","iman",125,"wo"); //iman_add("test",2,$iman,4,"error.php?a=1","view.php"); Quote Link to comment https://forums.phpfreaks.com/topic/66327-solved-the-specification-of-the-good-code/#findComment-331877 Share on other sites More sharing options...
MadTechie Posted August 23, 2007 Share Posted August 23, 2007 no idea its hard to read as you didn't use the code tag(#) OK after a quick look $lenght isn't needed (use count), and $error,$succ i would handle on the returned page so replace the header with return true/false and on the return redirect of course the script can be improved that just after a quick review and that my personal view function fun_add($tab,$id,$iman,$lenght,$error,$succ) { if ($id==0){//its insert function ! $res=("insert into $tab ()values()"); mysql_query($res); $id=mysql_insert_id(); }//end if // Get table Info $res1=mysql_query("desc $tab "); $c=0; while ($row1=mysql_fetch_array($res1)){ $c=$c+1; $fname[$c]= $row1[0]; } //2 to the first field acept id $q="update $tab set "; for ($i=0; $i<$lenght ; $i++) { $fi=$i+2; $q.="$fname[$fi]= '".$iman[$i]."' "; if($i!=$lenght-1) $q.=","; } $q.=" where id = '".$id."'"; //print $q; mysql_query($q) or die("not query"); if ( mysql_affected_rows()>0) { header("location:"."$succ"); exit; } else { header("location:"."$error"); exit; } } //$iman =array("hi","iman",125,"wo"); //iman_add("test",2,$iman,4,"error.php?a=1","view.php"); Quote Link to comment https://forums.phpfreaks.com/topic/66327-solved-the-specification-of-the-good-code/#findComment-331889 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.