Jump to content

CroNiX

Staff Alumni
  • Posts

    1,469
  • Joined

  • Last visited

  • Days Won

    12

Everything posted by CroNiX

  1. Are you actually using the php cli from cron? Or are you doing something like using wget?
  2. Since you should be running cron jobs via cli... if (php_sapi_name() != "cli") { die('No Remote Execution'); }
  3. I never understand why people write basically the same thing over and over just changing one little thing. Also, why complicate things and use php to output html? Just use html and output the php as needed. It's a lot easier to read, you don't have to do crazy things with extra quotes and editors will be able to properly parse/pretty print/type hint it. <?php if($values['store_id'] == "OTH") { echo '<div class="new-store-container" id="new-store-container" name="new-store-container" style="display:block;">'; } else { echo '<div class="new-store-container" id="new-store-container" name="new-store-container" style="display:none;">'; } ?> could be written as <?php $style = ($values['store_id'] == "OTH") ? 'block' : 'none'; ?> <div class="new-store-container" id="new-store-container" name="new-store-container" style="display:<?php echo $style; ?>;">
  4. So, you want to query the db in order to retrieve another query, which then you'll presumably execute? That's 2 queries when it should just be one. Doesn't sound very efficient. Why not just execute the query you want to run in the first place?
  5. Sounds more like a personal rant rather than specific criticism.
  6. @mac_gyver, true, but that's what he specifically asked: "the next username is the same as current"
  7. $last_user = ''; //track the last user while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $user = $data[0]; if ($user !== $last_user) //if the current user isn't the same, store as last user and display name { $last_user = $user; echo "User Name: $user"; } echo "Booking IDs: $data[1]"; }
  8. \/+[a-z0-9-]+\/checkout\/+[a-z0-9-]+\/thank-you This seems to work, at least when testing with preg_match(), does it look correct with the rules I stated? I basically escaped all slashes and chained everything together with a + that wasn't static. I think (lol)
  9. For google analytics, I need to have a regex that will match our goal pages. The part of the url that it would be looking at would be similar to: /variable/checkout/variable/thank-you These urls will have exactly 4 segments. "variable" segments can contain only letters (case insensitive), numbers, dashes and are required. I need to specifically match "checkout" in the 2nd segment and "thank-you" in the 4th. There is no trailing / after thank-you. Any help would be greatly appreciated. Regex is my weakness. (I know...I know..)
  10. Most languages allow this. Its only if you want more than one statement to be executes as the result of the if/else do you need to include them in braces. That being said, it is poor coding practice, looks ugly, and is harder to follow for lack of consistency. Best practice is to use braces around all if/else/etc conditionals, even singles.
  11. You asked how to get the size before the upload, and you can't because it isn't on the server yet and afaik, there is no javascript that will give you accurate results. You allow the upload, and then validate it once its on the server, including its size, and either accept the upload or reject it. There might be some flash upload script that can verify the size before upload, but you can't with php.
  12. spot on! Thank you very much! That replaced about 60 lines of code I was using to do this manually. I don't know why I have such a hard time wrapping my head around recursion.
  13. Hi, I have a multidimensional array where each array has a parent id node to create a hierarchical tree. $hierarchy[] = array('id' => 1, 'parent_id' => 0, 'name' = 'root1'); $hierarchy[] = array('id' => 2, 'parent_id' => 0, 'name' = 'root2'); $hierarchy[] = array('id' => 3, 'parent_id' => 1, 'name' = 'root1-1'); $hierarchy[] = array('id' => 4, 'parent_id' => 1, 'name' = 'root1-2'); $hierarchy[] = array('id' => 5, 'parent_id' => 3, 'name' = 'root1-1-1'); $hierarchy[] = array('id' => 6, 'parent_id' => 2, 'name' = 'root2-1'); I'm trying to come up with a recursive key/value search routine that will return all ancestor arrays of the found item without knowing the depth of the tree. All nodes with 0 for the parent_id are root level nodes. Basically I want to search for something like "where key = name and value = xxx" and have it return all ancestors of that node. So if I wanted to search for "key = name and value = root1-1", it should return and array like: array[0] = array('id' => 1, 'parent_id' => 0, 'name' = 'root1'); //parent node first array[1] = array('id' => 3, 'parent_id' => 1, 'name' = 'root1-1'); //first child after parent if I was to search for "key = name and value = root1-1-1", it should return: array[0] = array('id' => 1, 'parent_id' => 0, 'name' = 'root1'); //parent node first array[1] = array('id' => 3, 'parent_id' => 1, 'name' = 'root1-1'); //first child after parent array[2] = array('id' => 5, 'parent_id' => 3, 'name' = 'root1-1-1'); //first grandchild So the main problem comes in the iteration and keeping track of parents. If I just want the array with the answer I can get that node, but I can't get it with all of the ancestors attached. How would you go about this? Any good ideas out there? Thanks!
  14. Well gee, you make it so easy when you type it like that Thank you once again Aaron, works great!
  15. I need some help with a query that I haven't done before and have not yet succeeded. I have 2 tables. blog blog_comments ----- ------------ id id entry blog_id ... visible I am trying to: 1) select everything from blog 2) count comments left for each blog.entry 3) count comments left for each blog.entry where visible = 0 I got 1 and 2 accomplished using the following statement and need help getting #3. SELECT blog.id, blog.entry, Count(blog_comments.id) AS comment_total, FROM blog Left Join blog_comments ON blog.id = blog_comments.blog_id GROUP BY blog.id, blog.entry ORDER BY blog.`date` DESC Obviously the tables have a lot more fields, but this is the needed info to accomplish what I am after. If anybody could help I would appreciate it. Temporarily I am running 2 querries to get the data I need for #3 but would like to just have 1 statement and would like to learn this. Thanks for any insight!
  16. if you change this line: header('Location: http://www.patrickjudson.com/confirmation.php'); to: header('Location: http://www.patrickjudson.com/confirmation.php?fname=' . $firstName); then on your confirmation.php page you could: $fname = isset($_GET['fname']) ? $_GET['fname'] : ''; if(!empty($fname)) { //do your confirmation message } And now you can use $fname on the confirmation.php page
  17. Its a big security risk and should never had existed in the first place, if you are referring the the "registered globals"
  18. It probably doesn't matter, but GET should have quotes around it:
  19. Well, you didn't want to run the validation when there is no value, so thats what that does.
  20. if (isset($_POST['field_6']) && !empty($_POST['field_6'])) ??
  21. Thanks for taking the time thorpe. All of this info is stored in the database, and I will be changing the underscores to dashes there, no prob. The problem arises when someone has an old bookmark, I would like it to forward to the new one. Thanks again!
  22. Im doing some SEO optimization for a client and need to be able to change urls like: http://www.domain.com/something/some_other/oh_blah to: http://www.domain.com/something/some-other/oh-blah Basically change all underscores (_) to dashes (-) where ever they appear. Thanks
  23. Try running rawurlencode() on the address before displaying it in the browser. That should turn: http://www.mapquest.com/maps?city=Palm Beach into: http://www.mapquest.com/maps?city=Palm%20Beach
  24. Try running the code through a validator. I would bet that your html is not valid for the doctype that you specified.
×
×
  • 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.