Jump to content

skygremlin

Members
  • Posts

    41
  • Joined

  • Last visited

skygremlin's Achievements

Member

Member (2/5)

0

Reputation

  1. Thanx mac_gyver. I thought about putting the full page content in the DB and using one page file for display, but wasn't sure if putting html in the DB was the right path to take. Sounds like in this instance not a bad choice. thank you
  2. nah that didn't work, and that removes the css to my root/home.php...
  3. Folder structure with some additional data: root/css/main.css Inside the css file .header-news-events { background-image: url("../img/sub-img/sub-news.jpg"); } root/img/sub-img root/includes/header.php ​Inside the Header File <link rel="stylesheet" href="css/main.css"> <script type="text/javascript" src="js/main.js"></script> root/js/
  4. I also have url linking in my css file to yet another folder location.. From the css file that's ../img/sub-img/... Could that be messing with something? I thought the url links started at the css file location though..
  5. I've also tried this with same result.... $docRoot = ($_SERVER['DOCUMENT_ROOT']); echo'<script type="text/javascript">window.alert("Doc Root: '.$docRoot.'")</script>'; $headerLink = ($docRoot . "/css/header.php"); echo'<script type="text/javascript">window.alert("Another Link to Header: '.$headerLink.'")</script>'; include($headerLink); I think it's something more fundamental that I'm missing......
  6. Do you mean like this? include("/../includes/header.php"); If I do that I loose my header..
  7. I’m trying to organize a site and am missing something basic with linking my css.. Right now all the pages are in the root folder. I am using a template that includes a header and footer, only changing the body on each page. The header file contains links to the css and js files. I want to move all my news and events to a sub folder (newsEvents), as I expect a large number of these pages. For example: Folder structure: root/css/main.css root/includes/header.php root/newsEvents.php root/newsEvents/2014-04-29_eventPosting.php Working Page: root/newsEvents.php — loads css and javascript fine Inside of this page is the below line include(includes/header.php); Not working Page: root/newsEvents/2014-04-29_eventPosting.php — Does not load the css or the javascript Inside of this page is the below line include(../includes/header.php); I’m looking at the Debugger in FF, and I’ll see the CSS file listed for each page, but it shows 0 rules on the one not working. On the working page it shows 198 rules. I thought changing the includes path would be enough to load the header, which would included path’s to the css and js files.. But again, I’m missing something basic.. I’m using MAMP for my testing. If that makes a difference.. thank you
  8. Thanx mac_gyver and trq.. @mac_gyver I'm trying your suggestions and so far no luck... I'll play around some more and see if I can figure out what I'm doing wrong.. I'm sure it's something basic, I just need to do some more looking / research. @trq thank you. I think we're on the same page.. Hopefully just a poor choice of words on my part.. That being said what you posted helped me look at things from another angle. thanx guys
  9. I've fixed the undefined variable in the past with using !empty like below.. But for some reason If I use the below code it's still posting those errors. And my query doesn't seem to be working either... function __construct($config){ if(isset($config['host'])){ if(!empty($config['host'])){ $this->host = ($config['host']); echo'<script type="text/javascript">window.alert("Host is: '.$this->host.'")</script>'; } } if(isset($config['dbname'])){ if(!empty($config['dbname'])){ $this->dbname = ($config['dbname']); echo'<script type="text/javascript">window.alert("DBname is: '.$this->dbname.'")</script>'; } } if(isset($config['username'])){ if(!empty($config['username'])){ $this->username = ($config['username']); echo'<script type="text/javascript">window.alert("UserName is: '.$this->username.'")</script>'; } } if(isset($config['password'])){ if(!empty($config['password'])){ $this->password = ($config['password']); echo'<script type="text/javascript">window.alert("Password is: '.$this->password.'")</script>'; } } $this->open_connection(); }
  10. hmmm I made a couple changes with new results. I think I'm understanding what you meant.. Index.php: /** * If connected to DB load page * Else echo not connected */ if (isset($database)){ //echo "Database opened"; /** * Run query to verify working. */ $customers = cust_list($database->dbConn); echo "<pre>"; print_r($customers); echo "</pre>"; } else { echo "Database not opened"; } MySQL Database Class: class MySQLDatabase { /** * MySql Connect to DB */ private $host; private $dbname; private $username; private $password; public $dbConn; function __construct($config){ $this->host = ($config['host']); $this->dbname = ($config['dbname']); $this->username = ($config['username']); $this->password = ($config['password']); $this->open_connection(); } private function open_connection(){ try{ //$this->connection = new PDO('mysql:host=' . $host . ';dbname=' . $dbname, $username, $password); $this->dbConn = new PDO('mysql:host=' . $host . ';dbname=' . $dbname, $username, $password); echo '<script type="text/javascript">window.alert("Function: '.__FUNCTION__.' Line: '.__LINE__.'")</script>'; }catch(PDOException $e){ echo 'ERROR Inside the open_connection funtion: ' . $e->getMessage(); } } } /** * Create object */ $database = new MySQLDatabase($config); New Errors: Notice: Undefined variable: host in /Users/aaronjk/localhost/base_sites/php_base/includes/db_conn/MYSQL_database.php on line 29 Notice: Undefined variable: dbname in /Users/aaronjk/localhost/base_sites/php_base/includes/db_conn/MYSQL_database.php on line 29 Notice: Undefined variable: username in /Users/aaronjk/localhost/base_sites/php_base/includes/db_conn/MYSQL_database.php on line 29 Notice: Undefined variable: password in /Users/aaronjk/localhost/base_sites/php_base/includes/db_conn/MYSQL_database.php on line 29 Array ( [host] => localhost [username] => root [password] => root [dbname] => portal_db ) Array()
  11. I’m moving my code from Procedural to OOP and am having an issue trying to run a basic query. Looks like the connection to the DB is made, but I must not be fully understanding Objects / scope of Objects yet.. I’m trying keep it simple so I can test this out and understand it before updating my code. My instal thoughts are: 1. Get OOP class set up for DB Connection. MySQL first as that’s what I’m using now. Then config MSSQL and Oracle classes for easy integration. 2. Get simple queries working using a basic function file with PDO (Like current code). 3. Convert my function files to classes. I’ve separated my code to 3 function files (categories) for some organization. The files aren’t huge, but they do range from 150 lines to just over 1000. Below is the code I’m testing with. Pretty simple and I hope straight forward. I’ve also tried sending in $dbConn as a variable versus have it as a global variable in the function.. I’ve read that’s the better way. But if anybody has thoughts on that too I would love to hear opinions / recommendations. thanx Index.php - testing page: /** * Start Includes sections */ require_once("../includes/db_conn/MYSQL_database.php"); require_once("../includes/functions.php"); /** * End Includes sections */ /** * Check DB Connection */ if (isset($config)){ echo"<pre>"; print_r($config); echo"<pre>"; }else{ echo'<script type="text/javascript">window.alert("config not set")</script>'; } echo"<hr>"; //if (isset($database)){echo "Database opened"; } else {echo "Database not opened";} /** * If connected to DB load page * Else echo not connected */ if (isset($database)){ //echo "Database opened"; /** * Run query to verify working. */ $customers = cust_list($dbConn); echo "<pre>"; print_r($customers); echo "</pre>"; } else { echo "Database not opened"; } MySQLDatabase Class: class MySQLDatabase { /** * MySql Connect to DB */ private $host; private $dbname; private $username; private $password; public $dbConn; function __construct($config){ $this->host = ($config['host']); $this->dbname = ($config['dbname']); $this->username = ($config['username']); $this->password = ($config['password']); } private function open_connection(){ try{ //$this->connection = new PDO('mysql:host=' . $host . ';dbname=' . $dbname, $username, $password); $this->dbConn = new PDO('mysql:host=' . $host . ';dbname=' . $dbname, $username, $password); echo "<script type=\"text/javascript\">window.alert(\"Connection Made\")</script>"; }catch(PDOException $e){ echo 'ERROR Inside the open_connection funtion: ' . $e->getMessage(); } } } /** * Create object */ $database = new MySQLDatabase($config); Functions File (will be moved to a Class next): function cust_list($dbConn){ //global $dbConn; try{ /** * Prepare */ $cust_list = $dbConn->prepare("select * from customer"); /** * Bind */ /** * Execute */ $cust_list->execute(); /** * Fetch from array */ $cust_list_array = $cust_list->fetchall(PDO::FETCH_ASSOC); /** * Return */ return $cust_list_array; } catch(PDOException $e){ echo"Inside cust_list " . $e->getMessage(); } } When sending in $dbConn I get: Notice: Undefined variable: dbConn in /Users/aaronjk/localhost/base_sites/php_base/public/index.php on line 34 Fatal error: Call to a member function prepare() on a non-object in /Users/aaronjk/localhost/base_sites/php_base/includes/functions.php on line 12 When setting $dbConn as global inside the function I get: Fatal error: Call to a member function prepare() on a non-object in /Users/aaronjk/localhost/base_sites/php_base/includes/functions.php on line 12 From What I've read I "Call to member function prepare() on a non-object in.. " is because I need the global connection $dbConn set in the called function, but I thought I was doing that.
  12. Sorry let me restate these from initial example... Yeah I guess I could have them all in......2 tables... One for the actual job listing, the the other have columns for each of the requirements for the job...... I guess I wanted to keep things separate and not have a row with 15 columns with only 1 entry and a number of rows per job... But might be better the other way... Is that more the common approach? These are things I'm finding out as I go, and here... thanx for the help and advice.. job: PK - job_id job_info1 job_info2 job_info3 job_resp: PK - job_resp_id Foreign Key job_id job_resp_info job_duties: PK - job_duties_id Foreign Key job_id job_duties_info
  13. The number of queries could very well be my the issue.. A brief example: Table1: PK - tb1_id col_info1 col_info2 col_info3 Table2: PK - tb2_id Foreign Key tb1_id col_info1 col_info2 col_info3 Table3: PK - tb3_id Foreign Key tb1_id col_info1 col_info2 col_info3 So what I'm doing is taking the PK tbl1_id and getting all the items from table2 and table3 that have that id..
  14. Yeah sure - that balance between not enough info and to much... And in all fairness this may not be an issue at all.. My question is how I'm returning my ending result set from the function. My first query returns an array, but before that will be sent back, I'm using a value from that returned array to get more information (more arrays) and adding that to the end... So my initial array, now contains array elements inside of it. I'm concerned I'm doing a little to much work because my ending return has arrays inside of arrays inside of arrays... hope that helps a bit... if not I'll try again..
×
×
  • 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.