j1rd3ry Posted June 29, 2008 Share Posted June 29, 2008 ellow.... i just want to ask if this kind of coding style is acceptable...tnx in advance... (sorry about this...im just a newbie) class bBox{ //database information const hostname = "localhost"; const dbname = "tmp_database"; const user = "root"; const passwd = ""; //Pagination details const maxRows = 5; //maximum rows per page... public function DBconnect(){ $dbconn = mysql_pconnect(self::hostname,self::user,self::passwd) or trigger_error(mysql_error(),E_USER_ERROR); $dbselect = mysql_select_db(self::dbname,$dbconn); if($dbselect){ printf("DB connection status: Connected"); }else { printf("DB connection status: Disconnected"); } } function loginMember($user,$passwd){ $this->user = $user; $this->passwd = $passwd; $query = sprintf("select * from %s where username = '%s' AND password = '%s'",self::tableLogin,mysql_real_escape_string($this->user),mysql_real_escape_string($this->passwd)); $result = mysql_query($query); $rownum = mysql_num_rows($result); if ($rownum == 1){ $_SESSION['user'] = $this->user; echo "<br/><br/>[welcome..]"; }else { echo "<br/><br/>[username or Password Invalid]"; } } function display_pagenum(){ $this->display_pagenum = $this->totalpages; $page_number = 0; printf("<br/><br/><br/>"); while($page_number <= ($this->display_pagenum)){ if ($_GET['page_number'] == $page_number){ $page_number++; if($this->display_pagenum != 0){ printf("[<a href=\"{$_SERVER['PHP_SELF']}?pageNum=%s&totalRows=%s\">%s</a>] ",$page_number-1,$this->display_pagenum,$page_number); }continue; } printf("[<a href=\"{$_SERVER['PHP_SELF']}?pageNum=%s&totalRows=%s\">%s</a>] ",$page_number,$this->display_pagenum,$page_number+1); $page_number++; . . . . Link to comment https://forums.phpfreaks.com/topic/112410-just-want-to-ask/ Share on other sites More sharing options...
DarkWater Posted June 29, 2008 Share Posted June 29, 2008 See, the thing about coding OOP the way that you're trying to do it is that it would be better to code it procedurally. OOP is useless if you don't do it correctly, and especially if you just throw all sorts of functions into an object. Link to comment https://forums.phpfreaks.com/topic/112410-just-want-to-ask/#findComment-577392 Share on other sites More sharing options...
allenskd Posted June 29, 2008 Share Posted June 29, 2008 You might want to read http://www.phpfreaks.com/blog/learning-to-think-like-a-programmer Although the article itself doesn't prioritize the application design, you can still use it to idealize how your script will be like (like What class will manage what, who will rule over this class, who is going to extend this and that). (wonders if I'm making sense ) Link to comment https://forums.phpfreaks.com/topic/112410-just-want-to-ask/#findComment-577419 Share on other sites More sharing options...
keeB Posted June 29, 2008 Share Posted June 29, 2008 Short answer. No. Long answer. Hell no. I'll be a bit more helpful though You're on the right track. Taking an interest in making yourself a better programmer is step 1. Step 2 involved a lot of trial and error, and a ton of reading. It will take a long time to make the shift, to start thinking about low level components instead of the big picture. Some helpful material are: The tutorials on the main page: http://www.phpfreaks.com/tutorial/oo-php-part-3-uml-classes-and-relations Design Patterns : http://en.wikipedia.org/wiki/Design_Patterns Start reading peoples code in this forums and ask questions about things that don't make sense. We offer a lot of help, and thankfully we're not at the point of redundancy like the PHP Help forum. Link to comment https://forums.phpfreaks.com/topic/112410-just-want-to-ask/#findComment-577550 Share on other sites More sharing options...
j1rd3ry Posted June 30, 2008 Author Share Posted June 30, 2008 tnx...hehehe... next time i post, i'll make it sure that its acceptable.... thanks for the advice.... Link to comment https://forums.phpfreaks.com/topic/112410-just-want-to-ask/#findComment-577926 Share on other sites More sharing options...
448191 Posted June 30, 2008 Share Posted June 30, 2008 A good and easy guideline is to use 'responsibility driven design'. This is what the SRP is based on. See: http://www.phpfreaks.com/tutorial/oo-php-part-2-boring-oo-principles Your class is doing way too many unrelated things. Link to comment https://forums.phpfreaks.com/topic/112410-just-want-to-ask/#findComment-577945 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.