Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. Memcache: http://be2.php.net/memcache + what rhodesa said
  2. mktime($row['date']); should be: $joined_date = strtotime($row['date']); http://be.php.net/mktime requires it's parameters to be integers and if they are not they are converted to them abiding by the type conversion rules. print (int) "hello world"; // 0 Thus: mktime($row['date']); equals mktime(0); which equals the current date in seconds. Therefor $joined_date ~ $todays_date. Then you convert to days which is 0 as the difference between today and today is 0
  3. Is not an actual webpage as that would be hard to maintain they rather use .htaccess that converts the address to something like: index.php?section=models&id=1345 Can you give a specific url to the script you are trying to imitate then just the website?
  4. That's actually entire up to you, plus this should have been posted in application design or something.
  5. Not entirely sure that I get it but you select all alerts for a specific user and all alerts that have not been assigned to users, is this correct?
  6. echo "Success!"; header ("Location: http://www.ryanbuening.com"); Chicken and egg problem You want to display a success text however you also want to redirect the user but you can't as you have already sent information How about: <a href="somewhere">Proceed</a> Or before you output succes: header('Refresh: 0; URL=somewhere'); Increase 0 if it needs to wait longer
  7. Rhodesa can you explain this to me, as I don't exactly understand what you are doing here?
  8. messages --------- id message display_type ENUM('once', ..) NOT NULL DEFAULT once users ----- id username users_messages --------------- users_id messages_id read BOOLEAN NOT NULL DEFAULT FALSE SELECT m.* FROM messages m JOIN users_messages um ON m.id = um.messages_id WHERE um.users_id = % AND um.read = FALSE AND m.display_type = 'once' UPDATE users_messages SET read = TRUE WHERE messages_id = % AND users_id = %
  9. Do realize that this code has parts missing like validation. And if you would use this code as-is you will not be able to display form specific error codes.
  10. http://www.phpfreaks.com/forums/index.php/topic,261112.msg1230646.html#msg1230646
  11. You could list all files at once (and using javascript only display one branch at a time) or display upon request: Display upon request: $expand = $_POST['expand'];//don't forget to validate function create_tree($directory) { global $expand; $files = scandir($directory); print '<ul>'; foreach ($files as $file) { $basename = basename($file); if (is_dir($file)) { print "<li><a href=\"currentfile.php?expand=$file\"><img src=\"images/folder.png\" alt=\"folder\"> $basename</a></li>"; if ($file === $expand) { print '<li>' . create_tree($expand) . '</li>'; } } else { print "<li><a href=\"currentfile.php?expand=$file\"><img src=\"images/file.png\" alt=\"file\"> $basename</a></li>"; } } print '</ul>'; } create_tree(realpath('/path/to/expandable/directory')); This code is only intended to show you how you can faciliate this and is not intended for production use. A better aproach would be using the composite pattern. Edit: preferrably use mjdamato's solution, although I have one remark: why not create constants for the $to_return types? like DTA_RETURN_FILES?
  12. image/doc is not the mimetype of a word document it's application/msword
  13. This code isn't entirely correct, it will delete any post values on the last page: $_POST = array_merge($_SESSION['_POST'] /*stored values*/, $_POST /*post values from the last page*/); Should fix this problem.
  14. No, your code and SQL will still work you only need to adjust the paths. That's not true. If you have a file located in /includes/somefile.php and now I move somefile.php to /somedir. Then how will this code still works? require_once('/includes/somefile.php'); Consider to always use absolute paths using either realpath() or by defining directory constants: defined('__DIR__') or define('__DIR__', dirname(__FILE__)); //__DIR__ exists as of PHP 5.3.0 define('DOCUMENT_ROOT', __DIR__); require_once(DOCUMENT_ROOT . '/includes/somefile.php'); Personally I prefer realpath() as it modifies the directory separator to the underlying operating systems' directory separator.
  15. Nothing is ever really secure. When it isn't the code, it's the server, .. No one can ever guarantee 100% security, only 99.9% at its best however that 0.1% will come back to haunt you They have told me that your application's code is only as good as the company's worst programmer, and it's true. Even if computer's themselfs wrote it, it still wouldn't make it 100% proof. And don't believe everything they say, if we would believe everything they say we would have died a few times over In 2012 we will die again Ofcourse I'm not saying that you should just rely on any code but if you do - test it yourself - use unit testing for example (http://en.wikipedia.org/wiki/Unit_testing). If it passes all your worst case scenario's then you can be sure it will do to (for 99.9%) in the real world to.
  16. $news "CREATE TABLE `news` ( should be: $news = "CREATE TABLE `news` ( hence the =
  17. $content[] = $row->title; $content[] .= $row->content.'<br />'; is incorrect, what you actually should do is this (assuming you know what I mean with $i): $content[$i] = $row->title; $content[$i] .= $row->content.'<br />';
  18. OO is much more then just fancy classes, it's meant to improve re-use. Their are many techniques that you can apply that will improve the re-use of your code, one of these techniques is loose coupling. When writing classes you should make sure your class follows the Single Responsibility Principle (SRP, http://en.wikipedia.org/wiki/Single_responsibility_principle) and always remember to refactor your code when necessary (http://en.wikipedia.org/wiki/Code_refactoring) also don't repeat yourself (DRY, http://en.wikipedia.org/wiki/Don't_repeat_yourself) and keep it simple (KISS, http://en.wikipedia.org/wiki/KISS_principle) No it is not. Same applies for formatting directly in html (unless the classes's single responsibility is the formatting of data to html). Always make sure their is a clear separation of concerns (http://en.wikipedia.org/wiki/Separation_of_concerns) between your classes. When you are writing code always remember to stick to some identifier naming convention. It makes your code more readable and maintainable. Now to come back to your code and your actual question: when you write a class you need to think about the added value that this class makes to your application. For example you have created a Database class, however it has no added value. All it does is proxy MySQLi, actually your class is making it even worse as it limits the possible result set MySQLi provides. If I perform Database::select_query('..'); all I'll ever get is a numerical array? And what's worse of all, all my future tables needs to have a title and a content column. And if it has no added value then don't write it and use what's available.
  19. Use ExtJS as it more easily faciliates widgets: var tab1 = new Ext.Panel({ title: "Tab 1", autoLoad: "ajax.get-tab-contents.php?tab=1" }); var tab2 = new Ext.Panel({ title: "Tab 2", autoLoad: "ajax.get-tab-contents.php?tab=2" }); var tabPanel = new Ext.TabPanel({ renderTo: Ext.getBody(), activeTab: 0, deferredRender: false, items: [tab1, tab2] });
  20. Read this: http://www.tuxradar.com/practicalphp/18/1/10
  21. http://be.php.net/chmod
  22. Ok so you have one category table? Do you have a field which identifies the parent? Something like: category ---------------- id parent_id 1 0 // not a child 2 1 // child of 1 3 1 // child of 1 4 2 // child of 2 5 3 // child of 3 $currentCat = (int) $_GET['category']; while (list($id, $parent_id, ..) = mysql_fetch_array($result, MYSQL_NUM)) { if ($id === $currentCat) { $query = "SELECT * FROM categories WHERE parent_id = '$id'"; $result = mysql_query($query, $db); while (list(.. } If you are in for some complexity then take a look at the composite pattern as this will do here just nicely
×
×
  • 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.