Jump to content

Just want to ask... =)


j1rd3ry

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.