petersro Posted December 4, 2008 Share Posted December 4, 2008 Greetings all, im wanting to do a project with OOP, i have a coupple of question, rather noobish ones at that, after i pulled apart phpbb, i got rather lost in how it actualy worked, i understand database CRUD, but how does it form the pages, as there isnt any echo or whatnot, Second question is part of the first, how do i do skins, like on vbulletin, phpbb, ipb ect. from what i can tell there isnt any echo or other stuff, Quote Link to comment https://forums.phpfreaks.com/topic/135448-php-project-help-input-needed/ Share on other sites More sharing options...
premiso Posted December 4, 2008 Share Posted December 4, 2008 It uses templates to form the pages I imagine. But if you really want to know phpbb, check the forms and documentation. vbulletin and phpbb use styles to "skin" and they have users code in different templates so you change the template. Each template would require the design so you would have to do a design per template. I would like to help more, but the questions are really vague and the explanations are rather in-depth. You would need to talk to a phpbb guru to learn how it works etc. Quote Link to comment https://forums.phpfreaks.com/topic/135448-php-project-help-input-needed/#findComment-705657 Share on other sites More sharing options...
petersro Posted December 4, 2008 Author Share Posted December 4, 2008 thankyou for the reply, i do apologise for being so vague, trying to be more specific, i want to create a web app, that is similar to a few products on the market, basicly, mashing joomla vbulletin and CRM together, to form well a one stop shop, i have a basic understanding of php, and when reading the oop tutorial i have decided to go that way, however, i have no idea how to do say a basic login, using a template system, i understand the html/php way, but i have no idea where to begin with templates, im guessing that there is a functions_login, which has all the login functions, a functions_mysql, which has all the mysql functions (a global file), and a template_functions (another global file), that links all into the index.php and displays said form, all neatly with a skin arround it, i think im on the right track, but some sort of direction would be apreciated, Quote Link to comment https://forums.phpfreaks.com/topic/135448-php-project-help-input-needed/#findComment-706286 Share on other sites More sharing options...
premiso Posted December 4, 2008 Share Posted December 4, 2008 Check out smarty on google. That is probably the most widely used template system with a ton of documentation. That should help you get rolling on your templates. I think you can even store smarty templates in DB and retrieve that way without having 100 files on your server (I know VBB uses templates in DB) Anyhow hope that get's you rolling with templates. Quote Link to comment https://forums.phpfreaks.com/topic/135448-php-project-help-input-needed/#findComment-706289 Share on other sites More sharing options...
petersro Posted December 5, 2008 Author Share Posted December 5, 2008 thanks again, picking over smarty helped a great deal, i have through my quest come up against anew roadblock, i have skimmed through the forum, but havent found a complete answer, i can do basic CRUD with normal php, but with OOP, i have had some interesting issues, This is my current function_mysql.php <?php //Finding web root $dr=($_SERVER['DOCUMENT_ROOT']); //Loading system config require ($dr . 'config.php'); //System connection public function connect() { if(!$this->con) { $sys_connect = @mysql_connect($this->$db_host,$this->$db_user,$this->$db_pass); if($sys_connect) { $select_db = @mysql_select_db($this->db_name,$sys_connect); if($select_db) { $this->con = true; return true; } else { return false; } } else { return false; } } else { return true; } } //System disconnect public function disconnect() { if($this->con) { if(@mysql_close()) { $this->con = false; return true; } else { return false; } } } //System tables load private $result = array(); private function tableExists($table) { $system_tables = @mysql_query('SHOW TABLES FROM '.$this->$db_name.' LIKE "'.$table.'"'); if($system_tables) { if(mysql_num_rows($system_tables)==1) { return true; } else { return false; } } } //System select public function select($table, $rows = '*', $where = null, $order = null) { $q = 'SELECT '.$rows.' FROM '.$table; if($where != null) $q .= ' WHERE '.$where; if($order != null) $q .= ' ORDER BY '.$order; if($this->tableExists($table)) { $query = @mysql_query($q); if($query) { $this->numResults = mysql_num_rows($query); for($i = 0; $i < $this->numResults; $i++) { $r = mysql_fetch_array($query); $key = array_keys($r); for($x = 0; $x < count($key); $x++) { // Sanitizes keys so only alphavalues are allowed if(!is_int($key[$x])) { if(mysql_num_rows($query) > 1) $this->result[$i][$key[$x]] = $r[$key[$x]]; else if(mysql_num_rows($query) < 1) $this->result = null; else $this->result[$key[$x]] = $r[$key[$x]]; } } } return true; } else { return false; } } else return false; } //System insert public function insert($table,$values,$rows = null) { if($this->tableExists($table)) { $insert = 'INSERT INTO '.$table; if($rows != null) { $insert .= ' ('.$rows.')'; } for($i = 0; $i < count($values); $i++) { if(is_string($values[$i])) $values[$i] = '"'.$values[$i].'"'; } $values = implode(',',$values); $insert .= ' VALUES ('.$values.')'; $ins = @mysql_query($insert); if($ins) { return true; } else { return false; } } } //System delete public function delete($table,$where = null) { if($this->tableExists($table)) { if($where == null) { $delete = 'DELETE '.$table; } else { $delete = 'DELETE FROM '.$table.' WHERE '.$where; } $del = @mysql_query($delete); if($del) { return true; } else { return false; } } else { return false; } } //System update logic for($i = 0; $i < count($where); $i++) { if($i%2 != 0) { if(is_string($where[$i])) { if(($i+1) != null) $where[$i] = '"'.$where[$i].'" AND '; else $where[$i] = '"'.$where[$i].'"'; } else { if(($i+1) != null) $where[$i] = $where[$i]. ' AND '; else $where[$i] = $where[$i]; } } } $keys = array_keys($rows); for($i = 0; $i < count($rows); $i++) { if(is_string($rows[$keys[$i]])) { $update .= $keys[$i].'="'.$rows[$keys[$i]].'"'; } else { $update .= $keys[$i].'='.$rows[$keys[$i]]; } // Parse to add commas if($i != count($rows)-1) { $update .= ','; } } //system update public function update($table,$rows,$where) { if($this->tableExists($table)) { // Parse the where values // even values (including 0) contain the where rows // odd values contain the clauses for the row for($i = 0; $i < count($where); $i++) { if($i%2 != 0) { if(is_string($where[$i])) { if(($i+1) != null) $where[$i] = '"'.$where[$i].'" AND '; else $where[$i] = '"'.$where[$i].'"'; } } } $where = implode('=',$where); $update = 'UPDATE '.$table.' SET '; $keys = array_keys($rows); for($i = 0; $i < count($rows); $i++) { if(is_string($rows[$keys[$i]])) { $update .= $keys[$i].'="'.$rows[$keys[$i]].'"'; } else { $update .= $keys[$i].'='.$rows[$keys[$i]]; } // Parse to add commas if($i != count($rows)-1) { $update .= ','; } } $update .= ' WHERE '.$where; $query = @mysql_query($update); if($query) { return true; } else { return false; } } else { return false; } } ?> This is the config.php <?php $db_host = localhost $db_user = root $db_pass = ****** $db_db = test ?> This is a test to see if it works <?php; //Finding web root $dr=($_SERVER['DOCUMENT_ROOT']); //Loading what we need require ($dr . '/system/functions_mysql.php'); $res = $db->getResult(); print($res); ?> this is the output in the web browser getResult(); print($res); ?> Quote Link to comment https://forums.phpfreaks.com/topic/135448-php-project-help-input-needed/#findComment-706474 Share on other sites More sharing options...
premiso Posted December 5, 2008 Share Posted December 5, 2008 Different topic it should be. But you are not setting those as a class. <?php //Finding web root $dr=($_SERVER['DOCUMENT_ROOT']); //Loading system config require ($dr . 'config.php'); $config = array('db_host' => 'bob', 'db_user' => 'bob2'); // etc $db = new dbClass($connectionSettings); class dbClass() { //constructor public function __construct($config) { $this->db_host = $config['db_host']; // etc. // however I would just pass the parameters to connect and not store them as class variables. $this->connect($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name']); // this is assuming you passed in an array for $config. $config = null; // no need for the connection info to stay valid. } //System connection public function connect($db_host, $db_user, $db_pass, $db_name) { if(!$this->con) { $sys_connect = @mysql_connect($db_host,$db_user,$db_pass); if($sys_connect) { $select_db = @mysql_select_db($db_name,$sys_connect); if($select_db) { $this->con = true; return true; } else { return false; } } else { return false; } } else { return true; } } //System disconnect public function disconnect() { if($this->con) { if(@mysql_close()) { $this->con = false; return true; } else { return false; } } } //System tables load private $result = array(); private function tableExists($table) { $system_tables = @mysql_query('SHOW TABLES FROM '.$this->$db_name.' LIKE "'.$table.'"'); if($system_tables) { if(mysql_num_rows($system_tables)==1) { return true; } else { return false; } } } //System select public function select($table, $rows = '*', $where = null, $order = null) { $q = 'SELECT '.$rows.' FROM '.$table; if($where != null) $q .= ' WHERE '.$where; if($order != null) $q .= ' ORDER BY '.$order; if($this->tableExists($table)) { $query = @mysql_query($q); if($query) { $this->numResults = mysql_num_rows($query); for($i = 0; $i < $this->numResults; $i++) { $r = mysql_fetch_array($query); $key = array_keys($r); for($x = 0; $x < count($key); $x++) { // Sanitizes keys so only alphavalues are allowed if(!is_int($key[$x])) { if(mysql_num_rows($query) > 1) $this->result[$i][$key[$x]] = $r[$key[$x]]; else if(mysql_num_rows($query) < 1) $this->result = null; else $this->result[$key[$x]] = $r[$key[$x]]; } } } return true; } else { return false; } } else return false; } //System insert public function insert($table,$values,$rows = null) { if($this->tableExists($table)) { $insert = 'INSERT INTO '.$table; if($rows != null) { $insert .= ' ('.$rows.')'; } for($i = 0; $i < count($values); $i++) { if(is_string($values[$i])) $values[$i] = '"'.$values[$i].'"'; } $values = implode(',',$values); $insert .= ' VALUES ('.$values.')'; $ins = @mysql_query($insert); if($ins) { return true; } else { return false; } } } //System delete public function delete($table,$where = null) { if($this->tableExists($table)) { if($where == null) { $delete = 'DELETE '.$table; } else { $delete = 'DELETE FROM '.$table.' WHERE '.$where; } $del = @mysql_query($delete); if($del) { return true; } else { return false; } } else { return false; } } //System update logic for($i = 0; $i < count($where); $i++) { if($i%2 != 0) { if(is_string($where[$i])) { if(($i+1) != null) $where[$i] = '"'.$where[$i].'" AND '; else $where[$i] = '"'.$where[$i].'"'; } else { if(($i+1) != null) $where[$i] = $where[$i]. ' AND '; else $where[$i] = $where[$i]; } } } $keys = array_keys($rows); for($i = 0; $i < count($rows); $i++) { if(is_string($rows[$keys[$i]])) { $update .= $keys[$i].'="'.$rows[$keys[$i]].'"'; } else { $update .= $keys[$i].'='.$rows[$keys[$i]]; } // Parse to add commas if($i != count($rows)-1) { $update .= ','; } } //system update public function update($table,$rows,$where) { if($this->tableExists($table)) { // Parse the where values // even values (including 0) contain the where rows // odd values contain the clauses for the row for($i = 0; $i < count($where); $i++) { if($i%2 != 0) { if(is_string($where[$i])) { if(($i+1) != null) $where[$i] = '"'.$where[$i].'" AND '; else $where[$i] = '"'.$where[$i].'"'; } } } $where = implode('=',$where); $update = 'UPDATE '.$table.' SET '; $keys = array_keys($rows); for($i = 0; $i < count($rows); $i++) { if(is_string($rows[$keys[$i]])) { $update .= $keys[$i].'="'.$rows[$keys[$i]].'"'; } else { $update .= $keys[$i].'='.$rows[$keys[$i]]; } // Parse to add commas if($i != count($rows)-1) { $update .= ','; } } $update .= ' WHERE '.$where; $query = @mysql_query($update); if($query) { return true; } else { return false; } } else { return false; } } } ?> It also looks like you have some issues in that class. I would highly recommend reading more on OOP in PHP and finding better examples of how to use it, cause that just shows you are just guessing at it all without having the proper form. I would actually recommend looking at an already built mysql class and see how that is constructed. Anyhow hope that helps ya. Quote Link to comment https://forums.phpfreaks.com/topic/135448-php-project-help-input-needed/#findComment-706749 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.