Jump to content

JonnoTheDev

Staff Alumni
  • Posts

    3,584
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by JonnoTheDev

  1. Back to the original question South Korea, by far
  2. Transformers have been around since 1836 and are an Irish invention! Have a look for yourselves. http://en.wikipedia.org/wiki/Transformer The UK Invented the flushing toilet. Forget your iPhone. Where would you be without one of those?
  3. As Thorpe has said your design is bad. From your post I a real world scenario, a database has nothing to do with an image, an image has nothing to do with a forum (forum is a bit general, this should be split into component parts), and a forum has nothing to do with a database or a blog (again a blog is a bit general). Therefore, as classes they should not be inheriting each others methods. As I have stated i a previous post, if an object requires the use of another, there should be a method defined that can accept the object it requires. For instance, in your blog website there may be a function where a user could upload an image into their blog. In your blog class(es) there should be a method that deals with this functionality. Now this function will need to use a method within the image class to upload and manipulate the image. The blog class should NOT inherit the image class! A method in the blog class should accept the image object as a variable. The main point of OO programming is to separate all the components. This is called loose coupling. If everything is tied together it is tightly coupled meaning you wouldn't be able to take part of the structure and use it in another project without bringing a lot of unneccessary stuff along with it. Can you now see the problem with your thinking? You are definately not at this stage yet as you need more knowledge of OO programming, however there are what are called design patterns that are basically solutions to common issues in OO design. There is a solution to the problem in creating objects all over the place in your application called the Registry Pattern. I haven't read over this article completely but i'm sure you can do your own googling to find more info. http://www.phppatterns.com/docs/design/the_registry
  4. This is the code for 1 way where array 1 has 1 value and array 2 has more than 1. See if you can amment to do both ways. <?php $a1 = array('Arctictrek\'s Indiana' => array(6), 'Storm Kloud\'s Chosen to Win' => array(5), 'Storm Kloud\'s Keep the Win' => array(11), 'Storm Kloud\'s Hharmony' => array(12), 'Fire \'N Ice In Conclusion' => array(29), 'Jacbar Alaskan Black Night' => array(13), 'Rameslyn Cherokee Squaw' => array(14), 'Highnoons Kaskinampo of Jacbar' => array(27), 'Malnorska\'s Gypsy Lady' => array(28), 'Highnoons Loucheuse' => array(30)); $a2 = array('Arctictrek\'s Indiana' => array(6), 'Storm Kloud\'s Chosen to Win' => array(11), 'Storm Kloud\'s Keep the Win' => array(23), 'Storm Kloud\'s Hharmony' => array(24), 'Fire \'N Ice In Conclusion' => array(25,29), 'Jacbar Alaskan Black Night' => array(13), 'Rameslyn Cherokee Squaw' => array(14), 'Highnoons Kaskinampo of Jacbar' => array(27), 'Malnorska\'s Gypsy Lady' => array(28), 'Highnoons Loucheuse' => array(30)); // make sure both arrays have the same num elements if(count($a1) == count($a2)) { for($x = 0; $x < count($a1); $x++) { $key = key($a1); print $key."<br />"; $start_val = $a1[$key][0]; print "Start Value: ".$start_val."<br />"; for($i = 0; $i < count($a2[$key]); $i++) { print "Sum: ".$start_val."+".$a2[$key][$i]."<br />"; $equals = $start_val+$a2[$key][$i]; print "Equals: ".$equals."<br />"; } print "<br />"; next($a1); } } ?> Will produce Arctictrek's Indiana Start Value: 6 Sum: 6+6 Equals: 12 Storm Kloud's Chosen to Win Start Value: 5 Sum: 5+11 Equals: 16 Storm Kloud's Keep the Win Start Value: 11 Sum: 11+23 Equals: 34 Storm Kloud's Hharmony Start Value: 12 Sum: 12+24 Equals: 36 Fire 'N Ice In Conclusion Start Value: 29 Sum: 29+25 Equals: 54 Sum: 29+29 Equals: 58 Jacbar Alaskan Black Night Start Value: 13 Sum: 13+13 Equals: 26 Rameslyn Cherokee Squaw Start Value: 14 Sum: 14+14 Equals: 28 Highnoons Kaskinampo of Jacbar Start Value: 27 Sum: 27+27 Equals: 54 Malnorska's Gypsy Lady Start Value: 28 Sum: 28+28 Equals: 56 Highnoons Loucheuse Start Value: 30 Sum: 30+30 Equals: 60
  5. Sweet child of mine.. that is not the idea of OO programming. Objects instantiated from classes should mimic real world objects. They should be separated into their own space. If an object of type A requires the use of an object of type B then a method needs to be defined in A that can accept B as a parameter i.e <?php class A { function do_stuff() { } function i_need_obj_b_to_do_stuff(B $obj) { $obj->do_some_more_stuff(); } } class B { function do_some_more_stuff() { } } // usage $a = new A; $b = new B; $a->do_stuff(); $a->i_need_obj_b_to_do_stuff($b); ?>
  6. Your params in array_keys are the wrong way around. Take a look at the following: <?php $foo = array('a','b','c','d','a'); $keys = array_keys($foo, 'a'); print_r($keys); ?>
  7. RewriteBase / RewriteRule ^contact$ ?nav=Contact [L]
  8. This is the basic principle http://stackoverflow.com/questions/4818237/jquery-automatic-click-after-4-sec
  9. Use SEO friendly URLS throughout the site, always
  10. That's not going to work without the date in the correct format. (23/10/2011 will result in week 01, should be 42). You require the date as follows: YYYY-MM-DD <?php $a = '2011-10-23'; $week_num = date('W', strtotime($a)); echo $week_num; ?> Use the php manual to find answers http://php.net/date
  11. Are you saying that you want to test if the checkbox is selected or not? If so you would use the following example: $("#blocked").click(function() { if($(this).is(':checked')) { alert('checked'); } else { alert('unchecked'); } });
  12. Real basic, however Systems From individual PCs to networks including software / specific operating systems. Solutions What is offered in terms of hardware, software by the company. An example may be accounting software or Windows Server for a network server. Services This may range from hardware, software installation / sales to telephone or on-site technical support.
  13. if (!preg_match('/[@]/', $email)){ } Poor test for an email address. Is ne@il an email address? No. The second example provided by Drummin is much better.
  14. An undefined index or undefined variable error means that you are trying to use a function on, or trying to use a variable / array key that doesn't exist. Here is your first snippet of code: <?php $Page = isset($_GET["Page"]); if (!$_GET["Page"]) { $Page=1; } ?> The logic here is incorrect. $_GET['Page'] only exists if a value for Page is passed through the url. The first function that you use is isset(). If no Page parameter exists in the url then $_GET['Page'] is a reference to nothing and your isset() function is producing the error. You are using this funtion in the wrong way. It is not a function thats return value should be assigned to a variable. It is used to test the existence of a variable or array key. Here is a refactored version: <?php if(!isset($_GET['Page'])) { $Page = 1; } else { $Page = $_GET['Page']; } ?> You could also write this like: <?php $Page = isset($_GET['Page']) ? $_GET['Page'] : 1; ?>
  15. That's tough, really tough. I guess reference material is taken for granted these days, I don't think I could work without it.
  16. Ask the guy who started the following post http://www.phpfreaks.com/forums/index.php?topic=343512.0
  17. mod_rewrite is an apache module that is loaded within the httpd.conf file allowing you to use friendly urls. Rules are effectively regular expressions (use wikipedia if you are unfamiliar with the jargon) that match a friendly style url and convert back into it's original form so your script functions correctly. If the apache configuration is set to read .htaccess files (which it most likely is) then the rewrite rules can be defined there. They can also be within your httpd.conf
  18. no
  19. Find out where the website is hosted & complain to them. Submit a complaint to Google via the DMCA http://www.google.com/support/bin/static.py?page=ts.cs&ts=1114905
  20. Of course it will be. Like I stated, get a firewall! This is real basic stuff. Most networks are setup like this, why would yours be any different?
  21. Images should be accessible via the document root for the domain i.e http://www.xyz.com/images/test.jpg Not stored on some random part of your hard disk on a windows pc. You should be running a webserver like Apache or IIS do define the document root for your website. To get an image to display that it outside of the document root you would either have to copy it into the doc root folder i.e images/ or, as long as it has sufficient permissions use php to display it using the following: <?php if($image = @fopen('d:\\images\\sani.gif', 'rb')) { header('Content-Type: image/gif'); fpassthru($image); } ?>
  22. No probs. Really i'm neither for or against using PHP frameworks. If it is a very large project then it would be a recommendation. If it is a small to medium sized project then I probably wouldn't. I use my own framework library that covers most of the groundwork for any website of this size. I have only really worked with Zend and had a play with CodeIgnitor so I cannot say out of all of them which one is best. It's really a personal preference. What I would say is that if your project is going to have developers coming and going then I would go with a well known framework. I have never heard of Elgg.
  23. Separate the path into parts and take the bits you need i.e <?php $path = '/var/www/html/mywebsite/images/foobar.jpg'; $parts = explode('/', $path); $filename = $parts[count($parts)-1]; ?> <img src="/images/<?php echo $filename; ?>" />
  24. Yes, if you are constructing an array from a database query i.e <?php $result = mysql_query("SELECT name FROM users WHERE job='Web Developer'"); $developers = array(); while($row = mysql_fetch_assoc($result)) { if(!in_array($row['name'],$developers)) { $developers[] = $row['name']; } } ?> The array_unique() function removes duplicates from the array as I have stated, therefore the array will only contain red, green, blue in that order (indexes 0,1,2). If you want to sort an array you can use a variety of functions. Why not check over the php manual and read the examples: http://uk.php.net/sort There are loads of functions for sorting arrays in the left column. Also, data should really be sorted from your initial database query using ORDER BY, etc. Also I could only query unique records from my database so I do not have to have any filter logic in my application code i.e <?php $result = mysql_query("SELECT DISTINCT name FROM users WHERE job='Web Developer' ORDER BY name ASC"); ?>
  25. Probably true. A large application is more than likely going to have a team of developers working on it over time. Developers will come and go. Using an established framework means that a new team member will not have to trawl through thousands of lines of bespoke code to understand what it is doing. Don't forget, an application still has to be built using a framework. I would refer to this as from-scratch also, it's just that you already have all the nitty gritty bits like database connectors, session management, etc there for you. Nobody will ever write every line of code themselves in an application. Just think when you last made a website. Did you put a Google map, or adverts on it? Did you use a template engine? Did you add any JQuery? All these functions and libraries are or require frameworks. You include the JQuery framework in a scrip tag before you write any javascript. You include the Google maps API framework in a script tag before you add the javascript code to display a map. You include the Smarty template framework in your code before you can create template files for your website. People say they don't use frameworks when they do without realising it. No, a framework may add additional overhead if you are not using it all. If you only require a small amount of functionality that the framework can offer, there is going to be lots of redundant code included. Good frameworks are usually optimised so they only load the necessary objects when required, however like all code there can be bugs. If you use the framework's functionality in an unorthodox manor then it is also likely that the end result will be poor. True, however the client code using the framework should be inline with the coding standards. The team of developers must also use the same standards throughout. This should be a practice that is written down and given to all developers. Just because a framework might use the following standard: class My_Framework_Class { } $variable_name = ""; function Fuction_name() { } Does not mean that in my application I could write the following code: class myExtendedClass extends My_Framework_Class { } $variableName = ""; function someOtherFunction() { } No, it does not make it any easier. Frameworks save time, that's the main point because you have access to functions that do a certain job, meaning you would not have to write all the nitty gritty stuff yourself. If I want to add a new feature to a website, lets say a blog, how is a framework going to make it easier? I'm still going to have to write all the code to make it work, just less of it. If I wanted it easy, I would install a copy of Wordpress and link it into my site. Using a framework will mean that your code is object based, so it does have advantages such as not affecting other parts of a program when integrating new features. Essentially, using a framework should indicate that your code will be well structured, easy to follow, meaning that new functionality can be added with a relatively small amount of hassle. Completely bespoke code, over time can become a spaghetti like mess if not well documented.
×
×
  • 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.