Jump to content

xProteuSx

Members
  • Posts

    476
  • Joined

  • Last visited

Everything posted by xProteuSx

  1. Drummin, First, thank you for your reply. The problem with what you've provided me with is that data within $old_chores_array and $new_chores_array is all arrays as well, and must be compared solely by the first two numerical values, as separated by the | character. Hence: 7|1|0|5|0|0 = 7|1|0|5|3|0 = 7|1|0|10|0|0 and 7|1|0|5|0|0 != 8|1|0|5|0|0 != 7|11|0|5|0|0 Know what I mean? That's why I was originally using nested foreach loops.
  2. Looks like I'll be working on this yet another day. Please guys (and gals)! I really can't get this; I need your help. Thanks in advance.
  3. Updated code, because this is actually a multi-dimensional array: $duplicates = 0; $match = 0; $old_chores_array = array('7|1|0|5|0|0', '7|2|0|5|0|0', '7|3|0|5|0|0', '7|4|0|5|0|0', '7|5|0|5|0|0', '7|6|0|5|0|0', '7|7|0|5|0|0'); $new_chores_array = array ('7|1|0|5|0|0', '7|2|0|5|0|0'); print_r($old_chores_array); echo '<br />'; foreach ($old_chores_array as $oldchore) { foreach ($new_chores_array as $newchore) { $newchore = explode("|", $newchore); if (($oldchore[0] == $newchore[0]) && ($oldchore[1] == $newchore[1])) { $match = 1; $duplicates++; break; } } if ($match != 1) { $newchore = implode("|", $newchore); array_push($old_chores_array, $newchore); break; } else {$match = 0;} } print_r($old_chores_array); echo '<br />'; echo 'There were ' . $duplicates . ' duplicates.<br />'; Still get some silly output. To re-iterate: only indexes 0 and 1 of the inner-most array matter; these cannot be added to the old array. The output always points out the correct number of duplicates, but it ALWAYS adds the last array within Array2 to $old_chores_array, whether it is a duplicate or not. If you use the following array values: $old_chores_array = array('7|1|0|5|0|0', '7|2|0|5|0|0', '7|3|0|5|0|0', '7|4|0|5|0|0', '7|5|0|5|0|0', '7|6|0|5|0|0', '7|7|0|5|0|0'); $new_chores_array = array ('8|1|0|5|0|0', '8|2|0|5|0|0'); There are 0 duplicates, however only the last value of $new_chores_array is appended to $old_chores_array, but they both should be. I figure I have the array_push and/or break in the wrong place, but I just can't figure this one out.
  4. Here's a piece of code you can just throw into a PHP file to test: $duplicates = 0; $match = 0; $old_chores_array = array('7|1|0|5|0|0', '7|2|0|5|0|0', '7|3|0|5|0|0', '7|4|0|5|0|0', '7|5|0|5|0|0', '7|6|0|5|0|0', '7|7|0|5|0|0'); $new_chores_array = array ('7|1|0|5|0|0', '7|2|0|5|0|0'); print_r($old_chores_array); echo '<br />'; foreach ($old_chores_array as $oldchore) { foreach ($new_chores_array as $newchore) { if ($oldchore == $newchore) { $match = 1; $duplicates++; break; } } if ($match != 1) { array_push($old_chores_array, $newchore); break; } else {$match = 0;} } print_r($old_chores_array); echo '<br />'; echo 'There were ' . $duplicates . ' duplicates.<br />'; The output should be: Array ( [0] => 7|1|0|5|0|0 [1] => 7|2|0|5|0|0 [2] => 7|3|0|5|0|0 [3] => 7|4|0|5|0|0 [4] => 7|5|0|5|0|0 [5] => 7|6|0|5|0|0 [6] => 7|7|0|5|0|0 ) Array ( [0] => 7|1|0|5|0|0 [1] => 7|2|0|5|0|0 [2] => 7|3|0|5|0|0 [3] => 7|4|0|5|0|0 [4] => 7|5|0|5|0|0 [5] => 7|6|0|5|0|0 [6] => 7|7|0|5|0|0 ) There were 2 duplicates. Instead I get: Array ( [0] => 7|1|0|5|0|0 [1] => 7|2|0|5|0|0 [2] => 7|3|0|5|0|0 [3] => 7|4|0|5|0|0 [4] => 7|5|0|5|0|0 [5] => 7|6|0|5|0|0 [6] => 7|7|0|5|0|0 ) Array ( [0] => 7|1|0|5|0|0 [1] => 7|2|0|5|0|0 [2] => 7|3|0|5|0|0 [3] => 7|4|0|5|0|0 [4] => 7|5|0|5|0|0 [5] => 7|6|0|5|0|0 [6] => 7|7|0|5|0|0 [7] => 7|7|0|5|0|0 ) There were 2 duplicates. There were 2 duplicates, but none of them should have been added to the array.
  5. Help, please!
  6. I've been working on this too long, without having it figured out. Starting to get a bit 'kooky' at this point! I'm one stage away from retarded frustration. I have two arrays, such as these: Array 1 ( [0] => 7|1|0|5|0|0 [1] => 7|3|0|5|0|0 [3] => 7|4|0|5|0|0 [4] => 7|5|0|5|0|0 [5] => 7|6|0|5|0|0 [6] => 7|7|0|5|0|0 ) Array 2 ( [0] => 8|1|0|5|0|0 [1] => 7|2|0|5|0|0 [2] => 7|3|0|5|0|0 [3] => 7|4|0|5|0|0 ) I am trying to write a piece of code that will compare every value in array 2 to every value in array 1 and if the first 2 NUMERICAL values do not exist in Array 1, they are to be added to it. So, in the end, after comparison, Array 1 should look like this: Array 1 ( [0] => 7|1|0|5|0|0 [1] => 7|3|0|5|0|0 [3] => 7|4|0|5|0|0 [4] => 7|5|0|5|0|0 [5] => 7|6|0|5|0|0 [6] => 7|7|0|5|0|0 => [7] => 8|1|0|5|0|0 [8] => 7|2|0|5|0|0) The values 7|3|0|5|0|0 and 7|4|0|5|0|0 from Array 2 have not been added to Array 1 because 7|3... and 7|4... already exist in Array 1. So far, I've got something like this: $match = 0; foreach ($array1 as $data1) { foreach ($array2 as $data2) { if ($data1 == $data2) { $match = 1; break; } } if ($match != 1) { array_push($array1, $data2); } else {$match = 0;} } Where have I gone wrong?
  7. Man, I can't even begin to understand the function you wrote, PFMaBiSmAd (thanks, by the way). Got it working, however. Thanks a ton.
  8. I think that the problem with this method is that something like this 13|2|0|15|1|1~ 5|1|0|15|1|1~ will always sort the 13... ahead of the 5... because its treating the substrings as text, whereas they are numerical values divided by the '|' character. Therefore, these substrings should sort as follows 5|1|0|15|1|1~ 13|2|0|15|1|1~ on the basis that the first integer of each substring is sorted by first, hence 5 should be before 13.
  9. Is there a simple way of sorting data like this? $string = " 50|1|0|15|1|1~ 13|2|0|15|1|1~ 50|3|0|15|1|0~ 19|1|2|10|0|0~ 19|2|2|10|0|0~ 22|4|2|10|0|0~ 22|3|2|10|0|0~ 19|5|2|10|0|0~ 1|6|2|10|1|0~ 19|6|1|10|1|1 "; I treat this data as a string, and create an array out of it as follows: $individuals = explode("~", $string); Then I can divide up each individual as follows: foreach ($individuals as $individual) { $individual = explode("|", $individual); } How can I write something that sorts this data by $individual[0], $individual[1], and $individual[2], respectively and in that order?? After sorting I should get the following: $string = " 1|2|10|0|0~ 13|2|0|15|1|1~ 19|2|1|10|0|0~ 19|5|2|10|0|0~ 19|6|1|10|1|0~| 19|6|2|10|1|1~ 22|3|2|10|0|0~ 22|4|2|10|0|0~ 50|1|0|15|1|1~ 50|3|0|15|1|0 "; Help? I have no idea how to write such a function. Thank you guys.
  10. Thanks guys. Now that I know it has something to do with CRON, I'll figure it out. Cheers.
  11. I have a need for the execution of a script on a weekly basis. In this instance, I need the PHP script to start executing every Monday at 00:00:01 (very first second of the week). How can I achieve this??
  12. Yes, I would like to limit the password by disallowing non alphanumeric characters ... client's request. Can this be done in one preg_match statement?
  13. Got it to work ... I swear I tried 3 times before and it wouldn't run!!!!
  14. Yeah, I wanted something that would recognize the iPhone, iPad, as well. http://detectmobilebrowsers.com/ <-- NO WORKY http://stackoverflow.com/questions/1005153/auto-detect-mobile-browser-via-user-agent <-- NO WORKY http://www.russellbeattie.com/blog/mobile-browser-detection-in-php <-- NO WORKY http://mobiforge.com/developing/story/lightweight-device-detection-php <-- NO WORKY etc ... etc ... Believe me, I couldn't find a single script that did both things. I'm confident there is one somewhere out there but I have yet to find it.
  15. Forgot to mention: the solution I posted previously uses sessions and session variables. You can also put a hidden input on the second page, and re-use the variable on the third, like this: <?php echo '<input type="hidden" name="num_uploads" value="' . $_POST[numberFromFirstPageForm] . '" />'; ?> Then you can claim it on the third page by calling up the variable like this: echo $_POST['num_uploads'];
  16. On your second page use this code: session_start(); $_SESSION['num_uploads'] = $_POST['numberFromFirstPageForm']; Then on your third page you can use this variable as follows: session_start(); echo $_SESSION['num_uploads'];
  17. I'm creating a registration, and need users to add a password that is alphanumeric, 8-20 characters in length, and contains at least one number and one letter. I got this to work: if ((!ereg("^([a-zA-Z0-9]){8,20}$", $_POST['password'])) || (!preg_match("#^.*(?=.*\d)(?=.*[a-z]).*$#i", $_POST['password']))) { $error = true; } However, I am wondering if I can do this with a single preg_match statement. This complex ereg and preg_match stuff makes me light headed ... I haven't been able to find a similar example anywhere. Thanks in advance.
  18. Jeez, I figured it out. I was doing this: echo '<a href="add.html?id=' . $row[id] . '&name=' . $row[name] . '">Add</a>'; That is why I couldn't do this: <a href="add.html?id=' . $row[\'id\'] . '&name=' . $row[\'name\'] . '">Add</a> However, I can do this: <a href="add.html?id=' . $row["id"] . '&name=' . $row["name"] . '">Add</a>
  19. Actually, it turns out the problem was a little different than what I wrote before ... I am using code like this: <a href="add.html?id=' . $row[id] . '&name=' . $row[name] . '">Add</a> As you can see I am using variables like $row[id] instead of $row['id'] I can't get this to work: <a href="add.html?id=' . $row[\'id\'] . '&name=' . $row[\'name\'] . '">Add</a> And I'd rather not do this: $id = $row['id']; $name = $row['name']; <a href="add.html?id=' . $id . '&name=' . $name . '">Add</a> Any other ideas??? Please???
  20. I have been working on a PHP site on an actual server that is online. This is bad practice, and a huge pain in the ass as I need to upload all files to test whether the work. So I've installed XAMPP and have transferred my database and website to the root folder. Now I get these errors: Notice: Undefined index: username in C:\xampp\htdocs\members.html on line 19 This error is produced here: session_start(); $fc_user = ''; $fc_pass = ''; if (isset($_SESSION['fc_handle']) && isset($_SESSION['fc_password'])) { $fc_user = $_SESSION['fc_handle']; $fc_pass = base64_encode($_SESSION['fc_password']); } else if (isset($_POST['username']) && isset($_POST['password'])) { $fc_user = $_POST['username']; $fc_pass = base64_encode($_POST['password']); } else if ((($_POST['username'] == '') || ($_POST['password'] == '')) && (($_SESSION['fc_handle'] == '') || ($_SESSION['fc_id'] == ''))) /// <-- THIS IS LINE 19 { header("Location: http://www.familychores.com/index_coming.html"); exit; } I can't figure this out ...
  21. I was wondering if there was any code that would recognize whether a mobile device is browsing a website?
  22. Got it: function curPageName() {return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);}
  23. I am trying to create a script that alters the navigation div depending on the page the user is on. How do I get the current page using PHP?
  24. AyKay47: thank you; I'll look into that. Adam: will do!
  25. I am trying to tidy up the code for my site, and I have a ton of MySQL queries and variables that have not been unset/freed. Is there any way to view stored variables, other than session variables??? (because I know how to do that already)
×
×
  • 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.