Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. We'd have to see the actual code to know if there is a way to rewrite it using less conditions or a different structure. If your goal is just to reduce the line length you can either a) Use some temp variables to shorten the if -or- b) Separate the conditions onto separate lines. Eg, giving the original statement of: if(condition1 && condition2 && (condition3 && condition4) || (condition5 && condition6) || (condition7 && condition8)) a) $res1 = condition3 && condition4; $res2 = condition5 && condition6; $res3 = condition7 && condition8; if(condition1 && condition2 && $res1 || $res2 || $res3) b) if( condition1 && condition2 && (condition3 && condition4) || (condition5 && condition6) || (condition7 && condition8) )
  2. You could wrap a smaller query to reverse the order around the main query. Like this: mysql_query(" SELECT * FROM ( SELECT messageID, posterID, messageTime, message FROM chat_messages ORDER BY messageTime DESC LIMIT 5 ) as tbl ORDER BY messageTime ASC ");
  3. Showing the query in question as well as related tables/indexes would probably be more helpful then the mysql config.
  4. { and } are special to smarty so if you want to use them otherwise (like in JS or CSS code) you have to surround those blocks with the {literal} {/literal} tags.
  5. The construct {x,y} in a regex means that the previous item can occur a minimum of x times and a maximum of y times. In your case, there is no previous item so the construct does not make sense. That is why you are getting the warning. You need to define what pattern it is you want that repetition construct to apply to first. Judging by your error message, all your trying to do is check the length of the username in this line. Rather than use a regex you should just use strlen for that job. $len = strlen($username); if ($len < 3 || $len > 20){ //error } As for your foreach error, when you are assigning your error messages, your changing $this->error from an array to a string, and foreach cannot operate on a string. If you want to append the error messages to your error array, you need to assign them like so: $this->error[] = 'Your username must be 3 to 20 characters in length.';
  6. That does not check if $k exists on $this, it checks if $v is a false value. It's essentially the same as doing if (!$v){ } To check if the variable given by $k exists on the object, use property_exists or isset. if (!isset($this->$k)){ throw new custError(" '$k' is not a valid parameter"); } else { $this->$k = $v; }
  7. You need to build what looks like a query string and pass that to .send() eg: // create pairs index=value with data that must be sent to server var the_data = 'page_id='+encodeURIComponent(document.getElementById('txt2').innerHTML); var the_data2 = 'page_id2='+encodeURIComponent(document.getElementById('txt22').innerHTML); var post_data = the_data + '&' + the_data2; //..rest of code request.send(post_data);
  8. Your posted code does not make any sense. Your using a foreach on an array you just created which has only one element. Inside the foreach your doing an operation that seems mostly pointless. Here's a version of the code that I think maybe you intended, but not sure. I wrapped the foreach in an if statement so it will only run if your getAllRoster function returns an array. $rosterList = $this->bios->getAllRoster(); $allies = array(); $allies[''] = 'Please Select An Opion'; if (is_array($rosterList)){ foreach ($rosterList AS $ally) { $allies[$ally->id] = $ally->rosterName; } }
  9. do { $user->reset_token = $user->generate_password(32);. $count = ORM::factory('manager')->where('reset_token', '=', $user->reset_token)->count_all(); } while ($count < 1); That is what I would do.
  10. You could do that. Store some value in the session to indicate that one is in progress, and if that value is present show an error message saying they can only have one active session at a time. From the usability point of view though it may be nicer to have it written to support multiple tabs by either moving the data out of the session or passing on a unique token.
  11. kicken

    loops

    When you get to the point that $startNum is 20, you have the condition 20 < 20, which is false so the loop exits. You need to use <= (less than or equal to) to include 20 in the loop.
  12. You need to identify which specific query is causing the error and post just that, as well as the details for the tables involved (list of columns and their types, mainly). The code you posted has several queries, we have no way of knowing which of them (if any of them) is the problem query or why. You say your getting an unknown column error, that means one of your queries is attempting to use a column name that does not exist. In the error you posted it says customers_id, but in the first couple place I see in your code, you use the column named customer_id (no s). Probably you just made a small typo in one of your queries somewhere.
  13. What do you mean exactly ? perhaps giving an example, if that is ok of course. As mentioned, this code is how you put PDO into exception mode: $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); When you do that, then whenever there is an error PDO will throw a PDOException which will then be caught by your try/catch block.
  14. You don't need the if statement if you've configured PDO to use Exceptions for errors. You only need it when using other error modes. Syntax error, network failure, database corruption, possibly any number of things. It would be caught, provided your using exception mode. Your probably getting yourself confused because your reading different tutorials/sites that use different error reporting behavior when it comes to PDO. One place probably sets it to exception mode and just wraps try/catch around things. Another might set it to PDO::ERRMODE_SILENT or PDO::ERRMODE_SILENT and testing each action manually with an if statement (i do this).
  15. There is no way to identify a particular tab (or window for that matter) which made a request using just standard request variables. What you need to do is inject something that will work as the identifier into the request via either the url or post parameters. As you've experienced though, this is not fool-proof as users can do things that cause the ID to get lost (or shared). Why do you need to know which tab or window it was? Your app really shouldn't care about that kind of information.
  16. You will need to do your comparison check if you want to prevent the updated_on field from being changed when there was no content changes. MySQL would still update that even if the response value had not changed.
  17. You can just do the update regardless. Checking if it's changed or not just to avoid an update query is not worth while. MySQL will already check during it's update process if the field value has actually changed, and if not skip updating that field.
  18. You could install bind and run your own DNS if you wanted sure, but it's probably not necessary. You could try creating a dns entry in your registrar for *.domain.com which will make a wildcard subdomain so anything will end up working and going to the address given.
  19. Ditto. As far as I am concerned, PHP is just fine for what it's primary purpose is. Sure it's got it's quirks but most languages do. I tend to agree that it gets a bad rap due largely to the fact that it's forgiving of mistakes which makes it easy for novices to churn out some crap code. On the flip side of that though, it makes it much easier to create simple scripts for small/specific tasks.
  20. You could include a link to your facebook/twitter/whatever pages in your signature if you want. There's actually a spot in your profile to put in your facebook url. I don't think there is any need for any kind of integration beyond that. I for one am very much opposed to this social-media, share everything I do, link everything I have together move that seems to be taking over the internet. Not sure how the rest of the community feels on the subject.
  21. Your error messages shows your path with a \\boswinfs04\ prefix, but you did not include that in your code where you defined the path. You likely need to add that prefix there as well for the path to be valid.
  22. The example code you provided is a perfectly valid and commonly used application of that operator. Using it for small things like that is just fine. Some people will get a little crazy with it and try and put a ton of stuff into it which just ends up making the code complicated and hard to read. Basically, if used in moderation then it's fine and can even enhance code's readability. If abused though it can make for a nightmare.
  23. You can only loop through a result-set once. Your first while loop runs it to the end then your second at the bottom has nothing to do. Using a do...while loop with a result set is not correct either as it will execute the loop body before fetching the row which is wrong. After you do your query, load all the results into an array, then replace your two while loops you have now with a foreach() loop over that array.
  24. There are some places that offer managed dedicated hosting, which will give you a dedicated box but they will still take care of any software setup or configuration you need, just gotta contact them and tell you what you want done. This usually costs a bit more but for someone knew to the game it offers a nice fallback in case your either not comfortable doing it yourself or mess something up. Cheaper plans will be unmanaged which generally means the most your host will do for you is a system format or reboot, everything else is up to you. As far as learning, pick up a few books about linux administration. I don't know of any in particular to recommend but I've had good experiences in general with any book published by O'Reilly so you could try there. To practice you can download a virtual machine program such as VirtualBox and setup a linux distro similar to whatever is on your dedicated host. Then if you want to make some change on your host you can make a few attempts at it on your virtual machine before hand until you get it right and figure out the process.
  25. <input type="radio" name="approveLeave" value="H"> <input type="radio" name="approveLeave" value="W"> That will make two radio buttons on the page, and the user will only be able to select one or the other. When you submit them in your server-side script they will be under the field name approveLeave with a value of either H (if the first is picked) or W (if the second).
×
×
  • 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.