Jump to content

ricky spires

Members
  • Posts

    171
  • Joined

  • Last visited

Everything posted by ricky spires

  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"); }
  13. please also not that the forms are pulling from different databases
  14. mutli form submits in select dropdown? hello. im totally stuck. i need to create a drop down that lets me edit/delete the selected item but im so so so stuck i think its to do with the multi submit buttons at the moment when you select the first option, it works fine. its puts the corrct information in to the secont drop down but when you select the second drop down i get this error this is the code <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>"; ?> <?php if($getPropType <1){ echo'<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> <form name="submitCats" method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <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 $cats = Cats::find_by_parent($getPropType); $getCats = (isset($_GET['cats']) ? $_GET['cats'] : ''); echo "<select name='cats' class='select1css required'>"; echo "<option value='Select a Category' >Select a Category...</option>"; foreach($cats as $cat) { echo "<option>".$cat->name."</option>"; } echo "</select>"; ?> <input type="submit" name="submitCats" value="Select" class="submitBTN"/> </td> <?php if($getCats){ $cats = Cats::find_by_id($getCats); echo '<td>You selected:'.$cats->name; echo '<br><a href="edit_Categories.php?id='.$_GET['cats'].'">Edit</a> - <a href="delete_Categories.php?id='.$_GET['cats'].'">Delete</a> </td>'; }else{ echo '<td><span class="red-error">Please select a Category</span></td>'; } ?> </tr> </table> </form>
  15. hi all. Thanks for your replies. Its working now. THANKYOU. REF - Psycho How would i do that? is it a setting in phpmyadmin or something else ? thanks ricky
  16. hello i have a form which needs a parent id submitted but a cant get it to submit the id. all the other feilds go in fine. please could someone take a look. thanks ricky <?php require_once('../../includes/initialize.php'); if (!$session->is_logged_in()) { redirect_to("login.php"); } ?> <?php if(isset($_POST['submit'])) { $cats = new cats(); $cats->name = trim($_POST['name']); $cats->type_id = trim($_POST['type_id']); // INPUT DATE & TIME $date = date('Y-m-d'); $DT = date("Y/m/d H:i:s"); $cats->created = $DT; $cats->modified = $DT; if($cats->save()) { // Success $session->message("Property Category uploaded successfully."); redirect_to('list_properties.php'); } else { // Failure $session->message("There was an error adding your category."); redirect_to('list_properties.php'); } } ?> <?php include_layout_template('admin_header.php'); ?> <div id="adminWrapper"> <div class="adminLeft"><?php include_layout_template('admin_leftCol.php'); ?></div> <div class="back"><a href="index.php">« Back</a></div> <h2>Add Category</h2> <?php echo output_message($message); ?> <div id="User-form"> <form method="POST" name="form" id="form" action=""> <table> <tr> <td>Name:</td> <td><input type="text" name="name" placeholder="Enter a Category Name" class='select1css required' autofocus required/></td> </tr> <tr> <td>Parent Property:</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='type_id' value='" . $pType->id . "'>" . $pType->name . "</option>"; } echo "</select>"; ?> </td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" class="submitBTN" value="Add a Category" autofocus required/></td> </tr> </table> </form> </div><!-- end id="User-form" --> </div> <?php include_layout_template('admin_footer.php'); ?>
  17. that worked <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 id='propType' 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 . "</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>
  18. hello. i am looping throught a select form and want to add a title as the top option that does nothing when submitted but its giving me an error: i guess thats because it has no id . how do i make it so if the option says "Select a Property Type..." it gives an error message saying to select an option if submitted. plus get rid of that error? thanks rick <form name="submitPropType" method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table class="properties" width="550" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="350"> <?php $propType = Prop_Types::find_all(); $idSelectedByUser = (isset($_GET['propType']) ? $_GET['propType'] : ''); echo "<select id='propType' 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 == $idSelectedByUser ? " SELECTED='SELECTED' " : "") . ">" . $pType->name . "</option>"; } echo "</select>"; ?> <input type="submit" name="submitPropType" value="Select" class="submitBTN"/> </td> <?php if($_GET){ $propTypes = Prop_Types::find_by_id($idSelectedByUser); 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>'; } ?> </tr> </table> </form>
  19. how do i get and echo the selected <select> in a form ? hello. i have a select drop down and i would like it so that when i select an item it with echo the name and also get the id so i can edit/delete if i want. at the moment when i press the submit it echos the name but i cant get the id in a $val to put in to my edit/delete url. also after i press the button the value in the drop does not stay the same. this is the code. <table class="properties" width="550" border="0" cellspacing="0" cellpadding="0"> <tr><td > <form name="submitPropType" method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <?php $propType = Prop_Types::find_all(); echo "<select id='propType' name='propType'>"; foreach($propType as $pType) { echo "<option name='$pType->name'>$pType->id - $pType->name</option>"; } echo "</select>"; ?> <input type="submit" name="submitPropType" value="Select" /> <?php if($_GET){ echo 'You selected:'.$_GET['propType']; } ?> </form> </td> <td><a href="edit_prop_type.php?id='.$pType->id.'">Edit</a></td> <td><a href="delete_prop_type.php?id='.$pType->id.'">Delete</a></td> </tr> </table> .ps. maybe i could do it without the submit button using javascript ? thanks rick
  20. this is the code now: <?php $i=1; while($i<=4) { $no = (rand(1,4)); echo'<div id="videoHolder" class="vid'.$no.'"> <img src="assets/images/pic'.$no.'.jpg" alt="picture'.$no.'">'.$no.' </div>'; $i++; } ?> i get a blank div every now and then thanks
  21. damm. now every now and again a div disapears like its looking for 0 or 5 ?
×
×
  • 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.