Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. Well, not anymore, but he was insanely popular between 2000 and 2003. A lot of great music genres have disappeared over the years like the and the or (you might wanna reduce your sound volume before clicking). -- Yes like I already mentioned it's html5 That's because the original foreach contains a print_r() which is for debugging. Don't use the original foreach use mine as otherwise it won't be able to read the mp3 files out of the directory. No it is a textual representation of how I assumed your directory structure to be. Just put it here: <?php error_reporting(-1); ini_set('display_errors', 1); $mp3files = new GlobIterator('mp3/*.mp3'); ?>
  2. Yes it will: UPDATE users SET foo = 'bar' WHERE id = Throws that error because there is no right value which happens with a non existing variable.
  3. Like PFMaBiSmAd already mentioned are you running the file under http://localhost or are you running it inside the editor Komodo?
  4. 1. use mysqli instead of mysql http://php.net/manual/en/function.mysql-connect.php (look at the big red box) 2. separate php and html don't mix it. 3. always properly escape your sql arguments Getting the previous and next is not as simple as +1 and -1 because you may want to hide/delete a row in the future and the +-1 won't allow you to instead use a query: <?php $sql = " SELECT *, (SELECT max(id) FROM `%1$s` WHERE id < %2$d AND status = 'published') AS prev_id, (SELECT min(id) FROM `%1$s` WHERE id > %2$d AND status = 'published') AS next_id FROM `%1$s` WHERE id = %2$d AND status = 'published' "; $dbname = mysqli_connect('host', 'user', 'pass', 'dbname'); if (mysqli_connect_error()) { // todo add proper error handling here echo mysqli_error($dbname); exit; } $stmt = sprintf( $sql, mysqli_real_escape_string($dbname, $table_name), mysqli_real_escape_string($dbname, $_GET['id']) ); $res = mysqli_query($dbname, $stmt); if ($res === false) { // query failed // todo add proper error handling here echo mysqli_error($dbname); exit; } if (mysqli_num_rows($res) === 0) { // wrong id // you know the drill echo 'no such ID'; exit; } $post = mysqli_fetch_assoc($res); ?> HTML HERE <ul class="paginator"> <!-- previous --> <?php if ($post['prev_id']): ?> <li class="previous"> <a href="blog.php?id=<?= $post['prev_id'] ?>"><</a> </li> <?php endif ?> <!-- next --> <?php if ($post['next_id']): ?> <li class="next"> <a href="blog.php?id=<?= $post['next_id'] ?>">></a> </li> <?php endif ?> </ul>
  5. $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; Because I don't like repeating myself I tend to not use the array's directly, for example: class SilentArrayObject extends ArrayObject { public function offsetGet($offset) { if (!$this->offsetExists($offset)) { return null; } return parent::offsetGet($offset); } } $_SERVER = new SilentArrayObject($_SERVER); Then I can simply write: $referer = $_SERVER['HTTP_REFERER']; Which results in null when it does not exist (which is the default behavior anyway).
  6. In the end it's each to it's own on what editor you use. There is nothing you mentioned PHPStorm can't do, not even the live view or the element inspector except then that PHPStorm is smarter and through a plugin gives you the the live view instead of DW who makes sure you have ONE MORE browser you need to tweak your css to. I believe an editor should support and allow you to improve your workflow and use new tools, like Jade, CoffeeScript, and LESS as they are made available and routine tasks like running tests, checking builds, track time on/close/resolve/create tasks/bugs, among others that a professional developer uses on a daily basis. Why do you export from svn while you should actually create a new repo for your client and through an svn:external link to your cms repo. It will also allow you to commit to a live branch of your client to release software instead of opening your ftp client and upping all files, so 1980's. I hope you use a specific .htaccess that redirects any visitors to a maintenance page so that they don't see a broken website while you do this, right?. Because imagine something went wrong, it would leave the website broken until you fixed the problem, which can be as long as a few minutes till a few days. While with version control you can just revert your live branch to the earlier version and through a commit release it right away. -- When you have multiple clients on one server you create a symlink to centralize all your cms files which saves space although this may no longer be a valid argument since HDD is so cheap although it may on SSD drives. Don't use ChromePHP directly instead use it through Monolog, so that you can log to a file while not in dev-mode.
  7. Find an implementation on the net in a language you understand and "translate" it into the language that you want to use. That's what I did a while back with a point-in-polygon algorithm: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html It's important that when you "translate" between languages you carefully understand how both languages work and any assumptions the author made: In this case it's the use of short-circuit logic. Of course just "copying" between languages is not really challenging so read up on SIFT and how it works, take what you know and write test-cases (another class that will use your class, which doesn't have to exist at this point, and verifies the output), and start your implementation, extend your test-case as your knowledge about SIFT grows. Example tests could be: assertTrue(img.isSimilarTo(img)); // the same image is similar to itself assertFalse(mydog.isSimilarTo(me)); // i am not my dog
  8. It's better to use a loop. Your instructor may put in some other songs when reviewing your assignment. You are pointing to a directory instead of an actual file, the correct would be: <a href="C:\Users\test\Desktop\Main\xampp\htdocs\mp3\Gigi D'Agostino - L'Amour Toujours.mp3">Gigi D'Agostino - L'Amour Toujours</a> (Great music choice BTW ^^) When you now click, it will launch your default music program. Make the path relative or it won't work on your instructor's computer which likely results in 0, like this: <a href="mp3/Gigi D'Agostino - L'Amour Toujours.mp3">Gigi D'Agostino - L'Amour Toujours</a> This is relative to your htdocs. htdocs `- mp3/ `- index.php In your index.php you are now pointing to the mp3/ directory relatively since both are in the document root (htdocs). Like already mentioned you should turn on error_reporting your code is littered with syntax errors. error_reporting(-1); ini_set('display_errors', 1); -- Since the HTML5 effort it's possible to play music directly into a limited set of browsers: <?php $mp3files = new GlobIterator('mp3/*.mp3'); ?> <ul> <?php foreach ($mp3files as $mp3file): ?> <li class="mp3item"> <audio controls="controls"> <!-- 1. play the file if the browser supports it. --> <source src="mp3/<?= htmlentities($mp3file->getFilename(), ENT_QUOTES) ?>" type="audio/mpeg"> <!-- 2. embed flash player here and let flash play the file --> <!-- 3. let them download the file and play it in their default music player --> <a href="mp3/<?= urlencode($mp3file->getFilename()) ?>" class="mp3"> <?= htmlentities($mp3file->getFilename()) ?> </a> </audio> </li> <?php endforeach ?> </ul> What this does is list each file and: * present a play button if your browser supports it or * present a download link.
  9. Yes it does. But it needs to be able to recognize the path. When it can't it'll show up highlighted in yellow/orange. Then you either need to adjust the path add a / to the start or mark the stylesheet directory as a resource root. I use it to autocomplete classes and id's and to view all applied styles to a particular element.
  10. Well I use PHPStorm for pretty much everything. Ever since they introduced support for Jade, CoffeeScript, and LESS. My HTML, JS, and CSS days are over. When you create a new project in PHPStorm it allows you to select a skeleton structure to start from. In my case that is the HTML5 responsive template found at initializr. They also support certain frameworks like Symfony 2 and Doctrine 2 and allow you to run commands like symfony init-project foo and the like. In the background I have a script running (written for NodeJS) that checks wether any of those files changed and compiles them. PHPStorm detects these changes and automatically uploads them to my default server. I have the same setup for my composer.json file (which runs composer.phar update). They also support Live View for Chrome (and Firefox I think) which means I don't even have to hit F5 anymore, just ALT+TAB to my open browser which shows my latest changes/fuckups. IMO your editor should support your workflow and allow you to smoothen it further. PS: They also support viewing images in your editor, auto-complete paths inside href="", src="", url(), and require(), and dragging images/files to any of these. PPS: They also support remote development, but keep a local copy to work on (auto-upload when the editor loses focus). Try the trial, and select New Project > FTP. PPPS: I strongly recommend you check out Monolog and ChromePHP so that debug messages don't appear in your output but instead in your Web Inspector (F12 in Chrome) like a console.log() does. And your IDE should support stepping through code and creating breakpoints to inspect variable values. Also when you are doing OO development you should also consider PHPUnit or at the very least assert. I don't think many developers consider it at all, probably having something to do with the stigma you talked about and possibly because of it's crappy workflow support. I may try out their Edge Code though.
  11. .php is not matched hence the \\b on both sides in my regex. Another reason .php is not matched is because it simply is not in there. As you can see $job->getTextDescription(); which returns only text, not html. I store a stripped version of the HTML too though. Solr and Lucene are both full-text search engines and don't really fit my purpose, though I may use them for something else, as every word is then a tag. I would like to constrain it more to a set of tags.
  12. I am creating a job website, specific for web developers (me!) as a fun learning side project, that crawls other job websites, analyzes the content and tags each job post (eg. Drupal, Wordpress, Zend framework, Symfony, ..). It's the tagging that I am unsure of how I should proceed: As an experiment I wrote this: // remove noise $text = preg_replace('/[^a-z\\d\\s,.]/i', '', $job->getTextDescription()); $frontend = 'html\\d?|css\\d?|javascript|js|jquery|xml|xpath|mobile|seo'; $backend = 'php|(my|ms)?sql(ite)?'; $formats = 'json|xml'; $webservices = 'soap|rest'; $frameworks = 'drupal|facebook|wordpress|zend\\s?framework\\s?\\d?|symfony\\s?(\\d|components)?'; $tags = array($frontend, $backend, $formats, $webservices, $frameworks); preg_match_all( '/\\b('. implode('|', $tags) .')\\b/i', $text, $matches ); $tags = array(); foreach (array_unique($matches[0]) as $tagName) { $tag = new Tag(); $tag->setName($tagName); $tags[] = $tag; } return $tags; As you can see I am trying to tag as wide as possible eg. I would match: zendframework, zendframework2, zend framework2, zend framework 2 I am not asking for help with code, just the concept of tagging content in the best way possible. Anyone knows of a better way to tag content then using weird ass regexes like: zend\\s?framework\\s?\\d?
  13. <p align="center" class="style1">Server Location:</p> <p align="center" class="style3"> <a href="<?= file_get_contents('externalurl.txt') ?>">click here</a> </p> <br>
  14. This article explains how you can query posts having similar tags (look at #3 and #4): http://www.sergiy.ca/how-to-write-many-to-many-search-queries-in-mysql-and-hibernate/
  15. $val = $this->defaults[$key] ?: null; Means that $val === null when $this->defaults[$key] evaluates to false, it's the value of $this->defaults[$key] otherwise. You can use a Factory for that but then that only works at object creation time, so afterwards setting a value to false, means it will be false. You can use a Prototype, create an object that holds all the default values and use the clone keyword to create new objects from these defaults. But neither of these make sure that when you set a given property to false (what with boolean properties?) it will get set back to the default value. To do this you need to do something like: class SmallObject { private $data = array(); private static $defaults = array( 'color' => '..', 'size' => '..', ); public function __construct($data = array()) { $this->data = array_merge(self::$defaults, $data); } public function __set($key, $val) { if ($val === false) { $val = self::$defaults[$key]; } $this->data[$key] = $val; } public function __get($key) { return $this->data[$key]; } } Every new object will have these defaults set: $o1 = new SmallObject(); echo $o1->color, PHP_EOL; // .. $o1->color = 'bar'; echo $o1->color, PHP_EOL; // bar $o1->color = false; echo $o1->color, PHP_EOL; // .. $o2 = new SmallObject(array('color' => 'foo')); echo $o2->color, PHP_EOL; // foo
  16. See http://php.net/manual/en/language.oop5.late-static-bindings.php It already is. Like Neil already mentioned you are possibly going about this all wrong. You can simply clone an existing object. $prototype = new SmallObject(); // contains all defaults $newSmallObject = clone $prototype; $newerSmallObject = clone $prototype; Something that also may work is: class SmallObject { private $data; private $defaults; public function __construct() { //setup data and defaults $this->color = 'foo'; $this->size = 'bar'; } public function __set($key, $val) { if ($val === false) { $val = $this->defaults[$key] ?: null; } if (!isset($this->defaults[$key])) { $this->defaults[$key] = $val; } $this->data[$key] = $val; } public function __get($key) { return $this->data[$key]; } } $smallObject = new SmallObject(); $smallObject->color = 'bat'; echo $smallObject->color, PHP_EOL; // bat $smallObject->color = false; echo $smallObject->color, PHP_EOL; // foo Not sure either of these are an ideal solution for you either. Can you explain why you have opted to do it like this? Why do you need to be able to set them back to their default?
  17. Obviously by not creating the object inside the constructor... class SmallObject { private $default_object; protected function getInner() { if ($this->default_object === null) { $this->default_object = new static(); } return $this->default_object; } public function __set($key, $val) { if ($val === false) { $val = $this->getInner(); } $this->{$key} = $val; } } It does. Simply make it static. Static means it is shared across all instances. class SmallObject { private static $default_object; protected function getInner() { if (static::$default_object === null) { static::$default_object = new static(); } return static::$default_object; } public function __set($key, $val) { if ($val === false) { $val = $this->getInner(); } $this->{$key} = $val; } } Get out of that mindset of thinking that your consuming too much memory and that you should limit the number of objects you create. Pre-mature optimization is evil! First make it work, then make it work fast!
  18. Since you mention that capacity is dependent upon refno. it's clear that you need a product_refno table: product_refno (refno_id, prod_id, capacity, ..) This will not work as you might expect for the same reason: SHOW COLUMNS FROM TABLE `product_refno` would not work either. How will you for example make sure you only return the fields that you want to allow to filter upon? At some point you will still need to add in custom coding to hide certain columns. Which defeats your only argument for EAV. Don't be lazy, properly normalize your DB.
  19. I give up! I won't help you anymore.
  20. Your latest function: function time_elapsed_since ($postedDateTime){ $time = time() - $postedDateTime; // to get the time since that moment $tokens = array ( 31536000 => 'year', 2592000 => 'month', 604800 => 'week', 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second' ); foreach ($tokens as $unit => $text) { if ($time < $unit) continue; $numberOfUnits = floor($time / $unit); return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':''); } } echo 'Mr. Tharanga added his tutor profile ' . time_elapsed_since('+38 minutes') . ' ago'; Returns You need to subtract the $unit's from $time as per Barand's comment but apparently you don't want to listen/be helped.
  21. We have mentioned like 3 times now that you are exiting too early and you need to concatenate the output..
  22. On Mac/Chrome, not sure wether other OS's/browsers have this too, it has the nasty behavior to jump down when you try to expand the editor so that you can only expand it only for a few lines.
×
×
  • 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.