Jump to content

ricky spires

Members
  • Posts

    171
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

ricky spires's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Hello. I was doing a tutorial on how to build a layout manager for codeigniter and i have run in to a little trouble. In the welcome.php controller i have added $this->layouts->add_include('js/simple_js.js'); then in my default layout view i have added some code in the header to call the js file <head> <?php echo $this->layouts->print_includes(); ?> </head> then in the model i have this // Include js or css for specific pages private $includes = array(); // get the included js from the welcome controller public function add_include($path, $prepend_base_url = TRUE) { if ($prepend_base_url) { $this->CI->load->helper('url'); // Load this just to be sure $this->file_includes[] = base_url() . $path; } else { $this->file_includes[] = $path; } return $this; // This allows chain-methods } // load the array public function print_includes() { // Initialize a string that will hold all includes $final_includes = ''; foreach ($this->includes as $include) { // Check if it's a JS or a CSS file if (preg_match('/js$/', $include)) { // It's a JS file $final_includes .= '<script type="text/javascript" src="' . $include . '"></script>'; } elseif (preg_match('/css$/', $include)) { // It's a CSS file $final_includes .= '<link href="' . $include . '" rel="stylesheet" type="text/css" />'; } } return $final_includes; } if i add an echo inside the add_include() function i get the correct url to the file - http://my-site.com/js/simple_js.js if i do the below inside the print_includes() function i get an empty array. echo '<pre>'; print_r($this->includes); echo '<pre/>'; so ... im guessing this is not getting the info from the add_include() function ??? why is the array empty ??? private $includes = array(); thanks Ricky
  2. hello im having a problem with my if statement in wordpress the if is inside a function and includes another function. if i do this the_author_meta('linkedin', $author->ID); it echos out a linkedin address: uk.linkedin.com/pub/andrew-adie/b/858/985@adiemoi if have put it into a <a> tag to tidy it up echo '<h5><a href="'; the_author_meta('linkedin', $author->ID); echo '">Linkedin</h5>'; so now i get a link called linkedin. i want the link to only appear if the function "the_author_meta('linkedin', $author->ID);" is not empty so i tried this not im not sure if this is the correct way ??? if(the_author_meta('linkedin', $author->ID)){ echo '<h5><a href="'; the_author_meta('linkedin', $author->ID); echo '">Linkedin</h5>'; } also when i run this code i get this echoed out: uk.linkedin.com/pub/andrew-adie/b/858/985@adiemoi so it looks like its echoing the function from inside the if and the if is not working anyway because not getting any "Linkedin" links showing. so how can i get it to only show Linkedin links if the exist ? thanks rick
  3. Strange... FIXED IT all i did was to remove the <br/> from the bottom so instead of echoing body{ background-color: red; } #bookWrapper{ width: 1000px; background-color: #ccc; } it gives me body{ background-image: url("assets/images/uploads/retina_wood.png");}#bookWrapper{ width: 1000px; background-color: #ccc; }
  4. ok. i have ran in to an issue. its seems to olny allow 1 style at a time ? i.e if it echos back body{ background-color: red; } #bookWrapper{ width: 1000px; background-color: #ccc; } only the body{ background-color: red; } seems to work. if i remove body{ background-color: red; } then #bookWrapper{ width: 1000px; background-color: #ccc; } will work. any idea ? here is my code. on the page i have <!-- Custom Template Styles --> <style type="text/css"> <?php echo getStyles(); ?> </style> my function looks like this function getStyles() { if(isset($_GET['book_id'])){ $book_id = $_GET['book_id']; $categories = Properties::cat_by_book($book_id); foreach($categories as $category){ $propCat_id = $category->cat_id; $catNames = Cats::find_by_id($propCat_id); $cID = $catNames->id; $style = $catNames->style_type; $bProps = Properties::area_by_id($cID); foreach($bProps as $bProp){ $b_area_type = $bProp->area_type; } if($b_area_type == "styles"){ if($style == "none"){ echo $catNames->name.'{ '; }elseif($style == "id"){ echo '#'.$catNames->name.'{ '; }elseif($style == "class"){ echo '.'.$catNames->name.'{ '; } $books = Properties::sub_by_cat($propCat_id, $book_id); foreach($books as $book){ $subCats_id = $book->subCat_id; $subNames = Sub_Cats::find_by_id($subCats_id); echo $subNames->name.': '; $bookProps = Properties::find_by_book($book_id); foreach($bookProps as $bookProp){ $bp_id = $bookProp->id; $bp_client_id = $bookProp->client_id; $bp_book_id = $bookProp->book_id; $bp_page_id = $bookProp->page_id; $bp_area_type = $bookProp->area_type; $bp_type_id = $bookProp->type_id; $bp_cat_id = $bookProp->cat_id; $bp_subCat_id = $bookProp->subCat_id; $bp_media_id = $bookProp->media_id; $bp_content_id = $bookProp->content_id; $bp_value = $bookProp->value; $bp_format = $bookProp->format; if($book_id == $bp_book_id && $propCat_id == $bp_cat_id && $subCats_id == $bp_subCat_id){ if(!$bp_value == "" && $bp_media_id == "0" && $bp_content_id == "0"){ echo $bp_value.'; '; }elseif($bp_media_id != "0" && $bp_value == ""){ $media = Images::find_by_id($bp_media_id); $file = $media->filename; echo' url("assets/images/uploads/'.$file.'");' ; }elseif($bp_content_id != "0" && $bp_value == ""){ echo'content; '; } } } } echo'}<br/>'; }//end if } } } i goes roughly like this: - first i get the book id ($book_id) - then i get all the properties for the book - then if its a style - get the style type (id, class or none) - then echo echo $catNames->name.'{ '; gives the class or id name - then echo $subNames->name.': '; gives the style name - then echo $bp_value.'; '; gives the value name or echo' url("assets/images/uploads/'.$file.'");' ; gives an image thanks -
  5. FIXED i put that code in to a function and then called it back in a <styles> tag <style type="text/css"> <?php echo getStyles(); ?> </style>
  6. hello. I have set up a back end systm for adding styles to my web site but i can but mary up the backend with the front end? in the back end you can add a type, a category, a sub category and a value with is all added in to a database. if i put the code on my index page: <?php if(isset($_GET['book_id'])){ $book_id = $_GET['book_id']; $categories = Properties::cat_by_book($book_id); foreach($categories as $category){ $propCat_id = $category->cat_id; $catNames = Cats::find_by_id($propCat_id); $cID = $catNames->id; echo $catNames->name.'{ '; $books = Properties::sub_by_cat($propCat_id); foreach($books as $book){ $subCats_id = $book->subCat_id; $subNames = Sub_Cats::find_by_id($subCats_id); echo $subNames->name.': '; $bookProps = Properties::find_by_book($book_id); foreach($bookProps as $bookProp){ $bp_id = $bookProp->id; $bp_client_id = $bookProp->client_id; $bp_book_id = $bookProp->book_id; $bp_page_id = $bookProp->page_id; $bp_area_type = $bookProp->area_type; $bp_type_id = $bookProp->type_id; $bp_cat_id = $bookProp->cat_id; $bp_subCat_id = $bookProp->subCat_id; $bp_media_id = $bookProp->media_id; $bp_content_id = $bookProp->content_id; $bp_value = $bookProp->value; $bp_format = $bookProp->format; if($book_id == $bp_book_id && $propCat_id == $bp_cat_id && $subCats_id == $bp_subCat_id){ if(!$bp_value == "" && $bp_media_id == "0" && $bp_content_id == "0"){ echo $bp_value.'; '; }elseif($bp_media_id != "0" && $bp_value == ""){ echo'media;' ; }elseif($bp_content_id != "0" && $bp_value == ""){ echo'content; '; } } } } echo'}<br/>'; } } ?> the code above will echo out whatever styles i set in the back end. {note that i have not included code for media and content. only value inputs. i this case im setting the background color so the code above echos out. that all seems fine but how do i now get that to change my styles. i tried removing that code from the index page and putting it in to a styles.php page like this... <link rel="stylesheet" type="text/css" media="screen" href="assets/css/styles.php"> <?php header("Content-type: text/css"); ?> <?php require_once("includes/initialize.php"); ?> <?php if(isset($_GET['book_id'])){ $book_id = $_GET['book_id']; $categories = Properties::cat_by_book($book_id); foreach($categories as $category){ $propCat_id = $category->cat_id; $catNames = Cats::find_by_id($propCat_id); $cID = $catNames->id; echo $catNames->name.'{ '; $books = Properties::sub_by_cat($propCat_id); foreach($books as $book){ $subCats_id = $book->subCat_id; $subNames = Sub_Cats::find_by_id($subCats_id); echo $subNames->name.': '; $bookProps = Properties::find_by_book($book_id); foreach($bookProps as $bookProp){ $bp_id = $bookProp->id; $bp_client_id = $bookProp->client_id; $bp_book_id = $bookProp->book_id; $bp_page_id = $bookProp->page_id; $bp_area_type = $bookProp->area_type; $bp_type_id = $bookProp->type_id; $bp_cat_id = $bookProp->cat_id; $bp_subCat_id = $bookProp->subCat_id; $bp_media_id = $bookProp->media_id; $bp_content_id = $bookProp->content_id; $bp_value = $bookProp->value; $bp_format = $bookProp->format; if($book_id == $bp_book_id && $propCat_id == $bp_cat_id && $subCats_id == $bp_subCat_id){ if(!$bp_value == "" && $bp_media_id == "0" && $bp_content_id == "0"){ echo $bp_value.'; '; }elseif($bp_media_id != "0" && $bp_value == ""){ echo'media;' ; }elseif($bp_content_id != "0" && $bp_value == ""){ echo'content; '; } } } } echo'}<br/>'; } } ?> but that does not work.. If i remove that code and replace it with <?php echo $background = "green"; ?> body { background-color: <?php echo $background; ?>; } i get a green background ... so how can i get my to change the bg ?? thanks ricky
  7. Yipppeeeee. It worked:) public static function find_by_book($book_id) { return self::find_by_sql("SELECT DISTINCT cat FROM ".self::$table_name." WHERE book_id={$book_id} group by cat"); }
  8. thanks . looks like a good direction to investigate. p.s. there could be any number of book id's i.e: id - book_id - cat - item 1 - 1 - cat1 - item1 2 - 1 - cat2 - item1 3 - 1 - cat2 - item2 4 - 2 - cat1 - item1 5 - 3 - cat1 - item1 6 - 3 - cat2 - item2
  9. Hello . im having trouble with a loop. i want the title to only appear ones and have the items listed under each title but it seems to be echoing the title more than once. i want to output something like this: Category1 item1 Category2 item1 item2 etc... but im getting this: Category1 item1 Category2 item1 item2 Category2 item1 item2 in my database i have this: id - book_id - cat - item 1 - 1 - cat1 - item1 2 - 1 - cat2 - item1 3 - 1 - cat2 - item2 my loop looks like this: //this part finds the categories by book id. $book_id = "1"; $bookCats = Categories::find_by_book($book_id); //this part finds the books categories foreach($bookCats as $bookCat){ $cat_name = $bookCat->category; echo $cat_name; //then in put the rest of the code here..... } this is how part of the class looks public static function find_by_book($book_id) { return self::find_by_sql("SELECT * FROM ".self::$table_name." WHERE book_id={$book_id}"); } the above code gives me: i want it to only give me thanks ricky
  10. Hello. Thanks for all your help .. however im having trouble getting it to work my db row looks like this: name: modified type: timestamp NULL: yes default: CURRENT_TIMESTAMP my class is like this: (see the full code at the end) class Cats extends DatabaseObject { protected static $table_name="prop_cats"; protected static $db_fields = array('id', 'type_id', 'name', 'created', 'NOW()'); public $id; public $type_id; public $name; public $created; public $modified; <?php // If it's going to need the database, then it's // probably smart to require it before we start. require_once(LIB_PATH.DS.'database.php'); class Cats extends DatabaseObject { protected static $table_name="prop_cats"; protected static $db_fields = array('id', 'type_id', 'name', 'created', 'NOW()'); public $id; public $type_id; public $name; public $created; public $modified; // Common Database Methods public static function find_all() { return self::find_by_sql("SELECT * FROM ".self::$table_name." ORDER BY name"); } public static function find_by_id($id=0) { $result_array = self::find_by_sql("SELECT * FROM ".self::$table_name." WHERE id={$id} ORDER BY name LIMIT 1"); return !empty($result_array) ? array_shift($result_array) : false; } public static function find_by_parent($getPropType) { return self::find_by_sql("SELECT * FROM ".self::$table_name." WHERE type_id={$getPropType} ORDER BY name"); } public static function find_by_sql($sql="") { global $database; $result_set = $database->query($sql); $object_array = array(); while ($row = $database->fetch_array($result_set)) { $object_array[] = self::instantiate($row); } return $object_array; } public static function count_all() { global $database; $sql = "SELECT COUNT(*) FROM ".self::$table_name; $result_set = $database->query($sql); $row = $database->fetch_array($result_set); return array_shift($row); } private static function instantiate($record) { // Could check that $record exists and is an array $object = new self; // More dynamic, short-form approach: foreach($record as $attribute=>$value){ if($object->has_attribute($attribute)) { $object->$attribute = $value; } } return $object; } private function has_attribute($attribute) { // We don't care about the value, we just want to know if the key exists // Will return true or false return array_key_exists($attribute, $this->attributes()); } protected function attributes() { // return an array of attribute names and their values $attributes = array(); foreach(self::$db_fields as $field) { if(property_exists($this, $field)) { $attributes[$field] = $this->$field; } } return $attributes; } protected function sanitized_attributes() { global $database; $clean_attributes = array(); // sanitize the values before submitting // Note: does not alter the actual value of each attribute foreach($this->attributes() as $key => $value){ $clean_attributes[$key] = $database->escape_value($value); } return $clean_attributes; } public function save() { // A new record won't have an id yet. return isset($this->id) ? $this->update() : $this->create(); } public function create() { global $database; // Don't forget your SQL syntax and good habits: // - INSERT INTO table (key, key) VALUES ('value', 'value') // - single-quotes around all values // - escape all values to prevent SQL injection $attributes = $this->sanitized_attributes(); $sql = "INSERT INTO ".self::$table_name." ("; $sql .= join(", ", array_keys($attributes)); $sql .= ") VALUES ('"; $sql .= join("', '", array_values($attributes)); $sql .= "')"; if($database->query($sql)) { $this->id = $database->insert_id(); return true; } else { return false; } } public function update() { global $database; // Don't forget your SQL syntax and good habits: // - UPDATE table SET key='value', key='value' WHERE condition // - single-quotes around all values // - escape all values to prevent SQL injection $attributes = $this->sanitized_attributes(); $attribute_pairs = array(); foreach($attributes as $key => $value) { $attribute_pairs[] = "{$key}='{$value}'"; } $sql = "UPDATE ".self::$table_name." SET "; $sql .= join(", ", $attribute_pairs); $sql .= " WHERE id=". $database->escape_value($this->id); $database->query($sql); return ($database->affected_rows() == 1) ? true : false; } public function delete() { global $database; // Don't forget your SQL syntax and good habits: // - DELETE FROM table WHERE condition LIMIT 1 // - escape all values to prevent SQL injection // - use LIMIT 1 $sql = "DELETE FROM ".self::$table_name; $sql .= " WHERE id=". $database->escape_value($this->id); $sql .= " LIMIT 1"; $database->query($sql); return ($database->affected_rows() == 1) ? true : false; } } ?> on the edit page i commented out some come: if(isset($_POST['submit'])) { $findPropCats->name = trim($_POST['name']); /* INPUT DATE & TIME $date = date('Y-m-d'); $DT = date("NOW"); $modified = $findPropCats->modified = $DT; */ $findPropCats->update(); if($findPropCats->update()) { // Success $session->message = "updated successfully."; redirect_to('list_properties.php'); } else { // Failure $session->message = "there was an error updating"; redirect_to('list_properties.php'); } }
  11. the problem seems to be that when i press the second submit button it refreshes the first
  12. ok. here we go. there is alot This is the page that displays the drop downs <?php require_once("../../includes/initialize.php"); ?> <?php if (!$session->is_logged_in()) { redirect_to("login.php"); } ?> <?php $currentUser = User::find_by_id($_SESSION['user_id']); ?> <?php include_layout_template('admin_header.php'); ?> <div id="adminWrapper"> <div class="adminLeft"><?php include_layout_template('admin_leftCol.php'); ?></div> <h2>PROPERTIES</h2> <?php echo output_message($message); ?> <?php include("includes/prop-type.php"); include("includes/prop-cats.php"); ?> </div> <?php include_layout_template('admin_footer.php'); ?> This is the include page for form1 <form name="submitPropType" method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label><b>Property Types:</b></label> <table class="properties" width="590" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="15"> <?php if($currentUser->level == "admin"){ echo'<a href="add_prop_type.php">Add</a>'; } ?> </td> <td width="315"> <?php $propType = Prop_Types::find_all(); $getPropType = (isset($_GET['propType']) ? $_GET['propType'] : ''); echo "<select name='propType' class='select1css required'>"; echo "<option name='' value='' >Select a Property Type...</option>"; foreach($propType as $pType) { echo "<option name='" . $pType->name . "' value='" . $pType->id . "'" .($pType->id == $getPropType ? " SELECTED='SELECTED' " : "Select a Property Type...") . ">" . $pType->name . "" . $pType->id . "</option>"; } echo "</select>"; ?> <input type="submit" name="submitPropType" value="Select" class="submitBTN"/> </td> <?php if($getPropType){ $propTypes = Prop_Types::find_by_id($getPropType); echo '<td>You selected:'.$propTypes->name; echo '<br><a href="edit_prop_type.php?id='.$_GET['propType'].'">Edit</a> - <a href="delete_prop_type.php?id='.$_GET['propType'].'">Delete</a> </td>'; }else{ echo '<td><span class="red-error">Please select a Property type</span></td>'; } ?> </tr> </table> </form> This is the include page for form 2 <?php require_once("../../includes/initialize.php"); ?> <form name="submitCats" method="GET" action=""> <label><b>Categories:</b></label> <table class="properties" width="590" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="15"> <?php if($currentUser->level == "admin"){ echo'<a href="add_category.php">Add</a>'; } ?> </td> <td width="315"> <?php echo $getPropType; $propCats = Cats::find_all(); //$propCats = Cats::find_by_parent($getPropType); $getPropCats = (isset($_GET['propCats']) ? $_GET['propCats'] : ''); echo "<select name='propCats' class='select1css required'>"; echo "<option name='' value='' >Select a Category...</option>"; foreach($propCats as $pCats) { echo "<option name='" . $pCats->name . "' value='" . $pCats->id . "'" .($pCats->id == $getPropCats ? " SELECTED='SELECTED' " : "") . ">" . $pCats->name . "" . $pCats->id . "</option>"; } echo "</select>"; ?> <input type="submit" name="submitPropCats" value="Select" class="submitBTN"/> </td> <?php if($getPropCats){ $propCats = Cats::find_by_id($getPropCats); echo '<td>You selected:'.$propCats->name; echo '<br><a href="edit_prop_Cats.php?id='.$_GET['propCats'].'">Edit</a> - <a href="delete_prop_Cats.php?id='.$_GET['propCats'].'">Delete</a> </td>'; }else{ echo '<td><span class="red-error">Please select a Category</span></td>'; } ?> </tr> </table> </form> This is part od the class of the first form <?php // If it's going to need the database, then it's // probably smart to require it before we start. require_once(LIB_PATH.DS.'database.php'); class Prop_Types extends DatabaseObject { protected static $table_name="prop_type"; protected static $db_fields = array('id','name','created', 'modified'); public $id; public $name; public $created; public $modified; // Common Database Methods public static function find_all() { return self::find_by_sql("SELECT * FROM ".self::$table_name." ORDER BY name"); } public static function find_by_id($id=0) { $result_array = self::find_by_sql("SELECT * FROM ".self::$table_name." WHERE id={$id} ORDER BY name LIMIT 1"); return !empty($result_array) ? array_shift($result_array) : false; } This is part of the class for the second form <?php // If it's going to need the database, then it's // probably smart to require it before we start. require_once(LIB_PATH.DS.'database.php'); class Cats extends DatabaseObject { protected static $table_name="prop_cats"; protected static $db_fields = array('id', 'type_id', 'name', 'created', 'modified'); public $id; public $type_id; public $name; public $created; public $modified; // Common Database Methods public static function find_all() { return self::find_by_sql("SELECT * FROM ".self::$table_name." ORDER BY name"); } public static function find_by_id($id=0) { $result_array = self::find_by_sql("SELECT * FROM ".self::$table_name." WHERE id={$id} ORDER BY name LIMIT 1"); return !empty($result_array) ? array_shift($result_array) : false; } public static function find_by_parent($catParent) { return self::find_by_sql("SELECT * FROM ".self::$table_name." WHERE type_id={$catParent} ORDER BY name"); }
×
×
  • 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.