Jump to content

eldan88

Members
  • Posts

    488
  • Joined

  • Last visited

Everything posted by eldan88

  1. Nevermind. There was another file that that was included, using the same code which didn't have a $_GET that wasn't set
  2. Hey Guys, I have a simple if/else condition, and I keep getting an error "Undefined index: store" . I was wondering why its giving me thar error with the first if statment evalutes to true?? . Below is my code. Thanks! if(isset($_SESSION['store'])){ $store_name = $_SESSION['store']; } else { $store_name = trim($_GET["store"],"/"); }
  3. KevinM1. Oh okay I see what you are saying. I was reading about enterprise patterns in the book you actually recommeded me to read... (PHP Objetcs, Patterns, and Practice by Matt Zandstra) and the layout just looked very similar to your typical MVC structure..
  4. Hey Guys. I am learning about the Enterprise pattern, and to me it seems like its the same as the MVC pattern (which I learned about) Do they work the same?? For those who know Martin Fowler's Patterns of Enterprise Application Structure, that is what I am referring to as the enterprise pattern
  5. I am echoing out 2 radio input fields in a foreach statement. I would like to have the first option checked in all the radio input fields that gets echoed out. But for some reason it marks the radio input field "checked" all the way in the bottom. (The last one) How can I make it so that every input field that gets echoed out will be marked checked? Below is my code. Thank you for your help foreach ($menu_cat_options as $menu_cat_option){ <input type="radio" checked="checked" name="display_type" value="radio" >Radio <br> <input type="radio" name="display_type" value="checkbox">Check Box }
  6. Hey Guys. I am trying to create a time dropdown and increment eat by an an hour until it is lless than or equal to the end time. I am using the DateTime class to accomplish this. Now when I am trying to use a for loop to accompish this it does not work. Can anyone please help me out with this issue? Below is the code that I have $start_hour = new DateTime("now",new DateTimeZone("America/New_York")); $start_hour->setTime(6,00); $formatted_start_time = $start_hour->format("H:i:s"); $end_hour = mktime(11,45); for($start_hour; $start_hour <= $end_hour; $start_hour->modify("+60 minutes"));{ echo "<select name='cat_display_timeslot'>"; echo "<option>{$formatted_start_time}</option>"; echo "</select>"; } Thanks!
  7. Ahh okay. I was thinking there was a way to do it inside the abstract class. But that makes sense. Thank you
  8. Hey Guys. I am across this in a book and I am having a hard time understanding how I can try/catch this expception The code below will throw an exception if I add an unit object into Archer or LaserCannon object. Here is a quick example class UnitException extends Exception{} abstract class Unit{ function AddUnit(Unit $unit){ throw new UnitException(get_class($this)."is a leaf"); } function removeUnit(Unit $unit){ throw new UnitException(get_class($this)."is a leaf"); } abstract function bombardStrength(); } class Archer extends Unit { function bombardStrength(){ return 4; } } class LaserCannonUnit extends Unit { function bombardStrength(){ return 44; } } $laser_cannon = new LaserCannonUnit(); $laser_cannon->AddUnit(New Archer()); // This is not allowed When I run the client code I get the following error message Fatal error: Uncaught exception 'UnitException' with message 'LaserCannonUnitis a leaf' Can any please help me understand this?? Thanks!
  9. ahhh okay. I got it now. Thank you so much for making it more clear to me now
  10. Hey Barand. Thanks for providing the example. I understand it a little better, but I am stilll a little bit confused in some parts. 1) I don't understand how $a > $b if they are both strings and not numbers 2) Why would a negative number be sorted above $b isn't supposed to be below be since it a negative number? For example in the follwing example, how can $a be greater, less than or equal to $b?? .... That's what confuses me the most $a = array("Alex","jon"); $b = array("Mike", "jon"); echo "<pre>"; print_r(array_udiff($a,$b,function($a,$b){ if ($a < $b) { fb("I am coming out of the if (a < b)"); return -1; } elseif ($a > $b) { fb("I am coming out of the a > b"); return 1; } else { fb("I am coming out of the else"); return 0; }; }));
  11. Hey Barand, Thanks for the explination but I still can't seem to figure it out. What do you mean exactly by "Sort Above" also why would it sore above if its a negative number??? Also how is it logically possible to check if $a is greater than $b???
  12. Hey Guys. I am trying to understand how the array_udiff works but I am having a hard time understanding why the call back function returns a interger? How does that return value preform the camparison? For example in the code below, what does the return 0 , or return 1 or -1 have anything to do with the comparison? Thank you in advance! function myfunction($a,$b) { if ($a===$b) { return 0; } return ($a>$b)?1:-1; } $a1=array("a"=>"red","b"=>"green","c"=>"blue"); $a2=array("a"=>"blue","b"=>"black","e"=>"blue"); $result=array_udiff($a1,$a2,"myfunction"); print_r($result);
  13. Hey cyberRobot and Zane. I realized it was a problem with the width on the left frame. I took down 1% and it shows on the right frame now. From some reason when I added the "/n" it didn't fit in the right frame, until I changed with wdith to 34% from 35%
  14. Hey Guys. I am using php to output to frames. When I add an "\n" tag of even a PHP_EOL the second frame shows blank. The weird thing is when I view the page source I can clearly see the HTML of both frames... Can anyone help me resolve this issue? Thanks! $iframe = "<iframe src='menu_new.php' width='65%' name='menu' id='menu' title='Menu Frame' ></iframe>\n"; //iframe not working when adding the /n on this line $iframe .= "<iframe src='menu-items.php' width='35%' name='menu-items' id='menu-items' scrolling='yes' noresize='noresize' title='Menu Items Frame'></iframe>\n"; echo $iframe;
  15. Can someone please help me with this issue...
  16. Also I even tried adding the namespace to the extended class and my IDE says "Unnecessary fully qualified name" namespace lesson_one; abstract class Lesson { // Some code here } class Lecture extends \lesson_one\Lesson { }
  17. Hey Guys. I am new to using namespaces. I am trying to use it on the code below but it keeps giving me an error message saying Class 'lesson_one\Lecture' not found I am not sure what I am doing wrong here... I have provided an example below. I know there is a duplicate conditional statement. But I am just working with this code to test out the namespace. Any help would be really appreciated! namespace lesson_one; abstract class Lesson { protected $duration; const FIXED = 1; const TIMED = 2; private $costtype; function __construct($duration, $costtype=1) { $this->duration = $duration; $this->costtype = $costtype; } function cost(){ switch($this->costtype) { case self::TIMED: return (5* $this->duration); break; case self::FIXED: return 30; break; default: $this->costtype = self::FIXED; return 30; } } function chargeType() { switch($this->costtype) { case SELF::TIMED: return "hourly rate"; break; case self::FIXED : return "fixed rate"; break; default: $this->costtype = self::FIXED; return "fixed rate"; } } } class Lecture extends Lesson { } class Seminar extends Lesson { } //echo Lesson::FIXED; $lecture = new \lesson_one\Lecture("5", Lesson1::FIXED); echo $lecture->cost(). "<br>"; echo $lecture->chargeType(). "<br>";
  18. And then I would have to run another foreach loop on $get_categories?
  19. Hey Guys. I have a custom function that simply loops through an array and outputs the menu categories it finds in the array. The foreach loop passes the function an array and the function returns the the value. The problem is that the function returns that last value. Now I know some of you might say ... "Why don't you put the foreach inside the function and return the value when the foreach loop has been completed" The reason why is because I to use that foreach loop through another function as well. I was thinking about using globals to get the return value. But just wanted to get your perspective on the best option here. Please let me know what you guys think Thanks User Defined Function function displayMenuCategories($menu_category){ $display_menu =""; $category_id = $menu_category['menu_cat_id']; $display_menu .= "<div class='menu_cat'>{$menu_category['menu_cat_name']}</div><br>\n"; if(!empty($menu_category['menu_cat_desc'])) { $display_menu .= "<div class='menu_desc'>{$menu_category['menu_cat_desc']}</div>\n"; } $category_info = array("display" => $display_menu, "category_id" => $category_id ); return $category_info; } Foreach loop $left_menu_categories // Is the array that contains all the menu categories foreach($left_menu_categories as $left_menu_category){ $get_categories = displayMenuCategories($left_menu_category); } var_dump($get_categories);
  20. Requinix. I have a quick question. How is select statement prone to SQl injection when it doesn't preform any kind of inserting into the DB?
  21. I am revisiting my code to refactor it and debating if whether or not I should use mysql prepared statements. The only goal I am trying to accomplish, is to simply display menu items for a restaurant food ordering website. That's all. It will select menu items from a database and display them using a while loop. Upon reading the documentation in php's website. They said that prepared statements are more efficient when statements are repeated. But all I am doing is querying the table once and preforming a while loop when a user visits my page. So is it really necessary to use prepared statements other than the fact that is prevents SQL injection?
  22. Wow. Thanks Barand. I never knew there was a between operator
×
×
  • 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.