Jump to content

mikesta707

Staff Alumni
  • Posts

    2,965
  • Joined

  • Last visited

Everything posted by mikesta707

  1. you can use the ternary operator $name = (isset($_POST['name'])) ? $_POST['name'] : null; but thats not much better. Assuming you want to always check if the post variable is set before you assign it to a variable, i don't see a better way than an if statement
  2. There are already things being done and steps being taken to stop this. I personally don't care because im not an idiot, and don't fall for these stupid things. Perhaps its digital Darwinism at work and we should let it run its course.
  3. Well you aren't really wasting code. I was just saying that what the Math class does is basically one method that can (and perhaps should) be handled by the parsing class. Since all the math class does is create another class based on some regex, You can just get rid of that class all together and use the parser class to create one of the distance/whatever classes. Now for the inheritance topic, just look at your math question classes, like distance or whatever. Compare them all, and see if they all have certain attributes/methods that are the same (perhaps basic attributes, accessors, mutators, etc.) If they have a set of attributes and methods that are pretty much the same, you can put those things into a Base class, and derive all the other classes from it. There are many advantages to use inheritance here, and it will make your code easier (in my opinion) to update and add stuff. if you want to add certain functionality to all the math question classes, instead of adding it one at a time you can add it to the base class and viola.
  4. If all the math class does is decide which of 4 classes to create, why not create a function in the parsing class to do that? That seems like something a parsing function would do. But yeah, about the other classes (distance, and what not) When I was talking about inheriting functions, these would be a good example. Im assuming, since they all answer some sort of math based question, that they have some similar attributes and methods. you could have them all extend one class. That way, since they are all basically the same type, so you can pass them into functions that use type hinting easier. for example, assume the base class was called MathHandler, and we use that to derive our other more specific classes from it public function foo(MathHandler $math){ then you could pass any of the different classes into that function, and take advantage of polymorphism (if you wanted to). But this is just a suggestion, you could do it a few different ways. However, I think inheritance would make sense here
  5. well I would imagine all these difference classes do similar things? so they probably have similar attributes/methods? If not than disregard the above
  6. 1.) You can use MySQL's LIMIT clause to specify a certain number of rows returned. Example $query = "SELECT * FROM table LIMIT 50 ORDER BY id DESC";//get last 50 entries in database 2.) In addition to the IP address of the user, the $_SERVER super global has the referrer also (although beware, because this can be spoofed, and is sometimes not sent $referrer = $_SEVER['HTTP_REFERER'];
  7. How much information are you taking for the menu? just the dish name? ingredients? price? description? if there is a bit of information, depending on how many menu's you have, 1 table might get a little messy. Then again, multiple tables might be a little overkill. For a relatively small amount of data, I would just use one table with columns for each piece of information about a menu item, and, as you said, a restaurant_id to identify them
  8. im assuming that the `last` column is a varchar type ("SELECT * FROM AuthorInfo WHERE last='$v'"); try that, you have to surround strings in mysql with quotes, or else it thinks its a number/variable/keyword/something its not
  9. How is the class hierarchy set up? Does this "Distance" class inherit from the math class? do all classes inherit from a Question or whatever class? But yeah, I would say you have a good set up
  10. you could send a get variable, iE <a href='processing.php?file=$filename'>Delete this file</a> and on your processing page, you could catch that variable via $file = $_GET['file'];
  11. Well think about it. Generally, the more code you have, the more chances you have to open something up for attack. If you have a simple hello world program echo "Hello World"; There isn't really anything a hacker could do to hack into that script (and then into your server) Simple scripts are just that, simple. Simple to make, and simple to secure. Its much harder to make a really complicated program secure then a simple program. Look at an operating system. Thats really complicated, but its also really hard to make secure
  12. a column that you can store something unique at each article. For each article you could do something like SELECT * FROM comments WHERE archive_id=? and archive_id stores, say, the unique id's from the Archive table, or something to that will identify which article you are talking about
  13. you are also going to want to make a column in the comments table with a link for the Archive table (IE the primary key, title, etc) and then you could use that in the query
  14. That code doesn't help at all. How is your database configured. What tables do you have, and what columns are in those tables. At least post the query itself?
  15. Did you connect to the database before you tried that. There needs to be an active mysql connect resource before you use it
  16. the following line while($row=mysql_fetch_array($result)) basically stores 1 row from the result set into that variable (as an array). There are many mysql_fetch_XXXX functions, and I suggest looking at the manual for information about that. Now how to manipulate this data depends on how much data/what data/ and how you want to manipulate it. For example, if you want to echo the data out, you would do something like you did in your example. If you wanted to store the result set for info later, you can do $data = array();//this is what will hold our data while($row = mysql_fetch_array($result)){ $data[] = $row;//this will put the contents of $row into the array $data } print_r($data);//this will print the structure of the $data array with $data, you could then do whatever you wanted
  17. oh yeah sorry, brain fart. Kudos for checking the manual, thats rare around here but yeah, once you sanitize your inputs, I don't see much of a problem. Its a very simple script, so that doesn't leave much room for vulnerabilities. And your headers look fine to me
  18. Yeah, what you are talking about is finding the best word when compared to the context its in. I don't believe pspell takes the context into account. Similarly Levenshtein only considers the one word you have, and not what the context is. Besides, all Levenshtein would do is give you the difference between one word and another, and has no bearing on definition or whatever
  19. yeah I don't really know how that happened... Chrome started typing in this weird font for a min. but thats close, single quotes don't interpolate variables, so that header string is the literal string "Location:$location". Notice it uses the literal string $location rather than the value of that variable. You can easily fix this by concatenating, or using double quoes. Here is the former example header('Location :'.$location);
  20. $f=$_GET["file"]; you should escape that with mysql_real_escape_quote() $f=mysql_real_escape_quote($_GET["file"]); beyond that I would need more information. can anybody download anything? is there a user system? can certain users only download certain files? etc.
  21. ahh yes it should be class foo { function bar() { "I am Foo"; } }//end class class footoo extends foo { function bar() { parent::bar();//note the use of :: echo "And I am footoo"; } }
  22. $location = (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "predefined page"; then use $location in your header. something like that should do
  23. you are using the assignment operator, when you should be using the comparison operator If(mysql_num_rows($pictures) = 0){ should be If(mysql_num_rows($pictures) == 0){
  24. Except that he wants to take those 12 images and repeat each image 5 times (for a total of 60 images), and have those 60 images display randomly. are you suggesting he can't use a simple array to do this?
  25. It resolves scope =P Yeah the double colon ( operator is used when you want to access static properties, constants, and overridden methods http://php.net/manual/en/language.oop5.paamayim-nekudotayim.php check out the manual A quick example. Say we had a class, foo, and a class footoo that is derived from foo. If foo has a method, bar(), footoo can access that method, even if it overrode it, using the scope resolution operator class foo { function bar() { "I am Foo"; } }//end class class footoo extends foo { function bar() { parent::foo();//note the use of :: echo "And I am footoo"; } } There is more too it though, so check out the manual for the other uses, and examples Edit; Marcus beat me, but i feel this is worth posting
×
×
  • 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.