Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. data: {name: name, details: message, action: 'addcomment'}
  2. You have to create the exception, but a lot of the time this can be as simple as just extending the exception class, or some sub-class of it. eg: class FileOpenException extends RuntimeException { public function __construct($file, $mode){ $message = 'Failed to open '.$file.' in mode '.$mode; parent::__construct($message); } } Once defined then you can throw new FileOpenException($file, $mode) just like you would any other exception. In this example the constructor was overridden to accept more specific parameters rather than the default of a generic message. Generally when creating an exception you will either only override the constructor, or not override anything and just extend the class.
  3. kicken

    Left join

    For a strictly mysql answer, you could use GROUP_CONCAT to join all the comment texts together into a single string. You probably don't want to display them all as a single string and likely want other details such as who made the comment so that's not a great solution. A better solution is to use a separate query to fetch the comment details and then reference them as you display the statuses. You'd have one query that pulls the status information and like count, then a second query that pulls the comments for each status. As you read the status information you'd store it into an array indexed by the status ID. Then as you read the comments you can locate the status by the ID and append the comments to that array. After you've put together the comments and status information you'd loop the statuses and display them. $sql = ' SELECT s.stream_id , u.users_username , COUNT(l.likes_location_id) AS likeCount FROM stream AS s LEFT JOIN users as u ON (u.users_username = s.stream_username) LEFT JOIN likes AS l ON ( l.likes_location_id = s.stream_id ) GROUP BY s.stream_id ORDER BY s.stream_id DESC LIMIT 50 '; $result = $db->query($sql); $statuses = array(); foreach ($result as $row){ $statuses[$row['stream_id']] = $row + array('comments' => array()); } $idList = implode(',', array_keys($statuses)); $sql = ' SELECT c.comments_location_id , c.comment FROM comments c ORDER BY c.comments_location_id DESC WHERE c.comments_location_id IN ('.$idList.') '; $result = $db->query($sql); foreach ($result as $row){ $id = $row['comments_location_id']; if (isset($statuses[$id])){ $statuses[$id]['comments'][] = $row; } } foreach ($statuses as $status){ //display status. } Side note: Don't use * in your select. Specify which fields you need (even if it's all of them).
  4. It depends on what exactly you're wanting to handle. Mysql handles the database file locking for you automatically so you don't need to worry about two people doing simultaneous inserts/updates/etc. If you want to do something like prevent someone from changing a record while another person has it open in your admin interface, that you'll have to handle on your own through some means.
  5. Here's a basic run down of what you'd want to do: First, find out what IP range the ISP's router is assigning for DHCP requests. You can determine this by plugging in your PC directly to the router and looking at what IP you receive. Second, you need to choose 2 addresses that are on that same network, but outside the DHCP range. Probably just +1 and +2 to whatever the ISP's router IP address is would work as typically the DHCP range is set higher. I'll assume for example's sake that the ISP's router IP is 192.168.1.1 and it's DHCP server begins assigning addresses at 192.168.1.50 - Run a cable from the ISP's router to a LAN port on each of your other two routers. - Configure the Wired router with a LAN IP address of 192.168.1.2. Ensure DHCP is disabled. - Configure the Wireless router with a LAN IP address of 192.168.1.3. Ensure DHCP is disabled. - Connect your other devices to the routers and ensure they are setup to acquire an IP via DHCP. I believe that should work. You'll probably want to configure the routers while they are all separate by just plugging into each one directly with an ethernet cable. After they have been configured then you can put everything together and try it.
  6. Perhaps I should clarify then that by "more secure" I mean that it uses stronger encryption or has better infrastructure security (sql injections, secured servers, etc). EV just means you better know who exactly you're dealing with. As a consumer, this is a good thing for sure. As a business it would be a good thing as well if you can afford it. Just because you pay extra for a EV certificate does not mean your site is somehow more secure than some site with a non-ev certificate. More trustworthy, perhaps. Not more secure.
  7. Did you define the autoload function? If so, what is it defined as? $autoload = array('HTMLPurifier_Bootstrap', 'autoload'); spl_autoload_register($autoload, true, true); That tells PHP to call the HTMLPurifier_Bootstrap::autoload() function whenever it needs to load any undefined class. You need to have that function defined as a member of the class and it needs to try and locate the desired class. class HTMLPurifier_Bootstrap { public static function autoload($class){ //Find definition of $class //Load definition using require } } Your HTMLPurifier_Bootstrap::registerAutoload seems needlessly complex too. All you should need to do is call spl_autoload_register. I'm not sure why you have it doing all the other stuff. Seems like it's probably in some attempt to ensure your function is first in the chain, which is unnecessary.
  8. StartSSL offers basic certificates for free. You could use those for a single domain and get one later through one of the better known companies if you feel it necessary. The green address bar is something people are trained to look for. It doesn't necessarily mean the site is somehow more secure than one without the green bar. It just means the company/person that owns the site has been put through a more strict verification process so the certificate issuer has better information about who they really are.
  9. What is the code for your auto loader function? Have you checked that it is able to find the class files when requested and include them?
  10. You have to do a sub query that gets the maximum for each ID, then join against to get the specific row you're interested in using the maximum value. Your table don't really help with knowing what exactly you want, so this is just a guess. SELECT fields FROM main_table LEFT JOIN ( SELECT cid , MAX(fc_timestamp) as max_fc_timestamp FROM secondary_table GROUP BY cid ) maxResult ON maxResult.cid = main_table.cid LEFT JOIN secondary_table ON secondary_table.cid = main_table.cid AND secondary_table.fc_timestamp = maxResult.max_fc_timestamp Note that you'll still get duplicates if there are multiple rows with identical maximum fc_timestamp values. A unique constraint could mitigate this if appropriate. You'll want to make sure that you have an index on the cid and fc_timestamp columns so that the sub query will complete quickly based on the index.
  11. Because if the class is not defined, it starts calling autoload functions until one of them defines the class. PHPMailer has it's own autoloader registered to load it's classes. There can be a chain of different autoloaders. PHP will call each one in the chain until one of them defines the required class. If none of them define it, you get an error.
  12. I used to have that Netgear router, but I cannot remember if it has the right settings or not available in the configuration pages. A quick scan of the manuals I found online for both routers suggests that neither of them do. If you have a spare port on the LAN side of each router, the plug in the wire from the main router there rather than the WAN/Internet port. That should work just as well.
  13. Did you make sure to configure the router for the proper mode as well? That is the most important thing otherwise the router will create it's own sub network that is isolated from your main network. Post some screenshots of the routers configuration pages if you're not sure what the proper settings should be.
  14. You still build the SQL text dynamically, but bind whatever user-input needs to be used where necessary. EG: $params=array(); if ($someCondition){ $pp = "(ms.level = 'Beginner' || ms.level = 'Intermediate')"; } else { $pp = "ms.level = ?"; $params[] = $dd_level; } $sql = " SELECT ... FROM ... WHERE $pp "; //bind whatever is in $params
  15. My guess would be that your condition in the second query doesn't match anything (no row has id=$person_id) so the first method returns false. Verify that $person_id contains a valid ID and matches a row in your database.
  16. No, the sentence as a whole is the data item there. Data should be broken down into it's smallest desired unit possible. Based on your sample, each word is a separate piece of data, not all the words as a whole. For example, if the question was Enter your favorite pets: each pet type ("dog", "cat", "fish", etc.) is a piece of data and should be stored separately. The reason you want to store them separately is so that you can take advantage of the databases ability to search for and manipulate data. For example you want a list of unique pet types. As I showed, if the data is stored properly the database can give that to you with a simple query. If the data is stored incorrect as in your current case, then you have to add a bunch of extra processing on the PHP end to get what you want. The same is true if you want to do something simple like "Who said they like fish?", with your current setup you have to pull the data, break it up, and search for fish yourself. With a proper design you could just ask the database with select id from favorite_pets where pet_type='fish'. If you want to do further reading on the subject, google database normalization. As for your original post, if you really can't do anything about how it's stored, then you just need to write a script to do what you already put in words for the most part. - Query for all the data - For each row --- Split the field by spaces using explode or preg_split --- Merge the list of words with a list from previous rows - Run the large list through array_unique - Sort the list using sort $allWords = array(); while ($row=$db->fetch()){ $words = preg_split('/\s+/', $row['data_col']); $allWords = array_merge($allWords, $words); } $allWords = array_unique($allWords);
  17. How you present the data to your users or collect the data from them is irrelevant to how it should be stored in your database. If you want them to just enter a space separated list in a text box that is fine. However, before you store that data you should explode the data into separate words, then insert each word as a single item in it's own row. When you want to present the data, you can select all the words then implode them back into a list if you want (or wrap them into an HTML list structure).
  18. In the router configuration, there is usually a way to set it's mode between either Gateway mode or Router mode (options may be named differently). You need to make sure they are set both set to Router mode. If they are in gateway mode then each one will create a new sub-net for it's devices effectively isolating them from each other. Also make sure DHCP is turned off on them and let the main ISP's router handle address assignment.
  19. Before you go any further, you should fix your database. You should never be storing a list of values in a single column in a table. Instead you want to have each value be it's own row. This might mean another table if you have other data besides these values in your existing table. Once you've resolved that problem, then getting a list of unique values in alphabetical order is as simple as SELECT UNIQUE data_col FROM table ORDER BY data_col
  20. If you need to interact with some service PHP doesn't already have an extension for. Such as: - VNC Server - Game Server - IRC Server - etc If you need to write your own server. Such as: - Websocket Server - Game server - Data collection server - etc There are many reasons why you might need to use sockets. Basically any time you want to have two computers share information, you'll be using sockets. The question is whether you can make use of an already established protocol/service (for example a lot of stuff uses HTTP) or if you'll have to write your own custom protocol (for example games will do this to maximize efficiency). If you can't piggyback onto an existing protocol and use existing extensions, then you fall back to generic sockets.
  21. Generally you just avoid the obvious stuff, like don't run a bunch of queries in a loop, use a JOIN. Focus on just writing code using good standards that is easy to manage and maintain first, don't worry about trying to optimize it. Once it works you can start profiling the code and start introducing optimizations later when and where they are necessary. Yes it means you might end up re-engineering something but at the same time you avoid over-engineering something else that never would have been a problem in the first place. As for your original post's scenario with the mostly static menu, one thing that could be done is to store a pre-rendered menu into a memory cache such as Memcached or APC. Anywhere that you might do something which would affect the menu you would just wipe out the cache and let them all re-generate naturally on the next request.
  22. No it doesn't. It dump's to stdout, when you can then stream from your script to the end user directly.
  23. Ask your host if mysqldump is already available for you to use. They may have it installed already and give you the information necessary to use it. If you're absolutely stuck using PHP to dump the data though, then I would hex encode the blob columns. Then you don't have to worry about what characters need to be escaped vs which are ok as is. Just encode everything.
  24. The array lookup method would be best if you can define it just once, but reference it multiple times. Either define it in a class constructor, or if this function is standalone you could use a static variable and initialize it on the first function call. function getPath($path){ static $map; if (!$map){ //define array } if (isset($map[$path])) return $map[$path]; throw new Exception("Path {$path} not valid."); }
  25. Use whichever method you find most readable. The performance difference between the two is probably negligible (you could test it if your concerned/curious).
×
×
  • 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.