Jump to content

hkothari

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

hkothari's Achievements

Member

Member (2/5)

0

Reputation

  1. I'm just curious but are there any good books on PHP application design that anyone can suggest? I'm not looking for books that teach php basics, I got that down, but I'm looking more for the proper way to design a PHP web application.
  2. I know this is a complex topic and all, and you can't really protect your php software because in its executable from it's its source, but I was just wondering how companies require a key for their software to work like vBulletin for example? Like how do they require you to pay for it and have a key before you install it? Just curious. Thanks.
  3. You can use strpos() and str_replace to do something like this, very crude, but it might work $images = ""; $start = strpos($text, "["); $end = strpos($text, "]"); if($start && $end) { $images = str_replace(" ", " .jpg", substr($text, $start, $end - $start); $images .= ".jpg" } [code] This assumes there's only one set of brackets and that everything is exactly in the form you provided. This will just give you the image names.
  4. I could be wrong, but I believe that is the only way to get the values into an array.
  5. In loginsuccess.php take: <? session_start(); if(!session_is_registered(myusername)){ header("location:login.html"); } ?> and move it to the top.
  6. Well, it is called statically though because it's just doing one thing that's it, also each child class has different values for the two parameters so that's why I have to redefine it. So for example if the class was like a Cat and it inserted it into the table "cats" I redefine it in order to do this: static function create(array $fields) { $validFields = array("name", "somethingelse"); parent::create($fields, "cats", $validFields); } So not making it static wouldn't really solve my problem. But in each of the child classes though there could be a constant for the validFields and tableName so is there a way to access these constants in the abstract class?
  7. So, I have an abstract class that has a function called "create" which inserts stuff into the database if they are in the an array which is supplied as a parameter. It's a static function defined like this: /** * create($fields) * Creates a thing in the database using the supplied array of fields. * @param $fields the fields with keys as their column and values as their rows. * @param $validFields an array with a list of valid fields. * @param $tableName since this is a static function we need the table to insert to. */ static function create(array $fields, $tableName, $validFields) { $keys = ""; $values = ""; foreach($fields as $key => $value) { if(in_array("$key", $validFields) && !empty($value)) { $keys .= "$key,"; $values .="'$value',"; } } $keys = rtrim($keys, ","); $values = rtrim($values, ","); $mysql = new Mysql_Wrapper(); return $mysql->query("INSERT INTO $tableName($keys) VALUES($values)"); } and this works, it's in the main abstract class. Now to implement this I make a "create" function in the inheriting class and call the create function with the parameters, but I was wondering, since this is an abstract class, is there some way I can make some constant abstract fields in the class, and implement them in the inheriting class in order to remove the need of redefining the function in the inheriting class just to add the validFields and the tableName. Is there anyway to do this?
  8. Hm, that's weird, I'll check my code when I get home I guess, thank you anyways.
  9. That is my actual code, except I have a var_dump($array); at the end. $data = array(123, 140, 3123, 3000, 545); sort($data); var_dump($data);
  10. So I'm trying to sort a simple array with 5 numbers in it, defined as so: $array = array(123, 140, 3123, 3000, 545); Then I try to sort it using the sort() function as so. sort($array); and that didn't work, so I tried adding the SORT_NUMERIC parameter, but that didn't help. Then I tried to print the output of sort because I know it returns a boolean on success, but it didn't return anything. Does anybody know what's happening? I've tried var_dumping before and after the sort and nothing is done.
  11. I have a base class: class Base { function __construct($param1, $param2, $param3) { //does some stuff } } and a child class class Child extends Base { function __construct($param1, $param2) { //what I want to do here is call the parent constructor with the two given parameters and supply the third one. } } Is it possible to call the parent constructor when overloading it in the child class? Would calling: parent::__construct($param1, $param2, "third param"); work?
  12. What happens if I call mysql_query("INSERT INTO table (field1, field2, stuff, field3) ('value1','value2','value3', 'value4')") when the column 'stuff' doesn't exist? Does the query fail completely, is everything else inserted properly or something else?
  13. If I have a html form with 5 elements and I fill in 4 of them and submit it to another page. When I check to see which post values are there, will the 5th empty element also be there?
  14. If I want them to be on the same page, can I do a header redirect to the same page? And thank you.
×
×
  • 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.