Jump to content
Larry Ullman's Book Forums

Necuima

Members
  • Posts

    359
  • Joined

  • Last visited

  • Days Won

    7

Everything posted by Necuima

  1. I use Dreamweaver CS5 which I have found to be very good, but it is not free! Cheers
  2. Hi, If Larry can't fix the dropbox link, I will ask Larry to send you my email address, then you can email me and I will attach the code as files. Cheers from Oz.
  3. Hi Larry, Thanks for the feedback. I took the "IN" approach but the code was an object method which required me to create a 'dummy' instance, but it works just fine. As mentioned, I provided the list of database records that needed to be affected via a reference to the array which contained the database record keys. Again, I found the 'tasks' application a terrific one for learning and extension, first via procedural code and subsequently creating an OO version. Cheers from Oz.
  4. Just a general comment that there is also a powerful (and free) jQuery form validation plug-in that can be used. Cheers from Oz, Necuima.
  5. Hi, glad to see that you have figured out how to solve the issue. I'm assuming that you did a test for the number of rows returned from the "SELECT" and if there were no 'live' tasks in the database, did not try to populate the multi-dimensional array. The errors you received were because the array was empty. Cheers.
  6. Hi and welcome to the forum. Have you checked that there are still some tasks in the database that are not marked as completed? It seems possible that your database select is not returning any rows. You can check this via testing the row-count immediately after you have run the select query. If the row-count is zero (I usually check for less than 1) you can print a message saying that there are no 'live' tasks in the database. If the row-count is greater than zero, then go ahead with the population of the multi-dimensional array. $row_count = mysqli_num_rows($r); This 'tasks' exercise is one of my favourite learning exercises and I have found that you can extend it in many ways. Feel free to post more queries in this forum - a great community supports it. Cheers, Necuima.
  7. For anyone tempted to fetch the existing tasks from the database into Task objects, after a lot of trial and error the following works for me (from 'pursue', suggestion 6, page 282): function list_live_tasks(&$pdo) { // Run the query to select all non-completed tasks $q = 'SELECT task_id, parent_id, task AS task_name FROM tasks WHERE date_completed IS NULL ORDER BY date_added ASC'; $r = $pdo->query($q); if ($r->rowCount() <= 0) { echo "<p><font color='red'>There are no 'live' tasks in the database.</font></p>"; } else { $tasks = array(); // Initialize the storage array $obj = new Task(0, 0, NULL); // required by "FETCH_INTO" $r->setFetchMode(PDO::FETCH_INTO, $obj); // Add the results to the array while ($obj = $r->fetch()) { // the fetch populates the $obj instance of a Task object with attribute values from the database query $tasks[$obj->parent_id][$obj->task_id] = $obj->task_name; } unset($obj); echo "<h4> Live Tasks</h4>"; list_tasks($tasks[0], $tasks); // recursive function to list out the tasks } } If there is a better way, please share your thoughts. Thanks, Necuima.
  8. OK, am making good progress, but I have a question. In the 'mark as completed' processing, my database functionality does not act on one specific task object, as more than one task can be marked for completion at a time. I am using the "where task_id IN" approach as per Larry's example. So I create a 'dummy' task object and then use that to invoke the 'mark as completed' database functionality method and pass the other needed data to the method by reference. An alternative is to mark the selected tasks as completed one by one but that would require a database activity for each task - would that be 'better' though? Any thoughts and advice will be most appreciated. Cheers from Oz.
  9. From Stack Overflow I see that one can indeed include the MYSQL statements required to interact with the database as functions within the class. I will give it a go and if anyone is interested, will post the class definition if/when I get it to work! Cheers.
  10. Hi, I am tempted to try the 'pursue' suggestion on page 282, specifically setting up a 'task' class. My background experience is almost all procedural but I'm trying to expand my knowledge of OO. My specific question is: in setting up a 'task' class, would, say, the 'add' method include the MySQL required to add a task to the database? As an aside, I have found the tasks application a terrific one to 'pursue' with, and have just finished converting my (mainly procedural) already-pursued version to incorporate PDO. Cheers from Oz, Necuima.
  11. Hi Larry, What tools do you recommend for a desktop application that requires both read and write access to the file system on the desktop? Thanks, and Cheers.
  12. In general I fully agree with HartleySan and Larry in the context of Flex and Actionscript3 as web development tools. But I have done a couple of small applications using Flex/Actionscript3 which run on the desktop (via AIR). In this non-browser context I have found those tools very useful. Cheers.
  13. Hi HartleySan, As I said right at the very beginning, I was seeking advice on the best way to delete a key-value pair when you only know the value. Your advice and Google have helped me achieve my goal. I don't have enough detailed knowledge to make an informed judgement as to which way is best. I followed the lead http://www.programmerinterview.com/index.php/php-questions/how-to-delete-an-element-from-an-array-in-php/ which is the lead that I think you are referring to and right at the bottom is Bojangles approach. But as always I do appreciate your advice and insights. Cheers from my ageing grey cells here in Oz :-)
  14. Hi HartleySan, From: http://stackoverflow.com/questions/7225070/php-array-delete-by-value-not-key : This (array_diff) only works for objects that can be converted to a string - @nischayn22 It's worth noting that for some reason array_diff uses (string) $elem1 === (string) $elem2 as its equality condition, not $elem1 === $elem2 as you might expect. The issue pointed out by @nischayn22 is a consequence of this. If you want something to use as a utility function that will work for arrays of arbitrary elements (which might be objects), Bojangle's answer might be better for this reason - Mark Avery. Cheers from Oz.
  15. Hi HartleySan, I also found this approach in Stack Overflow courtesy "Bojangles": if(($key = array_search($value, $arr)) !== false) { unset($arr[$key]); } There was also a comment that the array_splice approach may not work in every circumstance. In your experience, is there any appreciable difference in the approaches? Re earlier, I just had not come across the array_search PHP function before and an earlier Google search did not reveal it. Cheers from Oz.
  16. Many thanks - I had just found the array_search approach via Google as you responded. Sorry to have bothered you!
  17. Hi, Can someone please tell me what the best way is to remove a key-value pair from a single-dimension array where you know the value but not the key. (In PHP). Any advice will be most appreciated. Thanks, Necuima.
  18. Hi HartleySan, Again, thanks for your interest. The book is PHP Advanced, 3rd edition, the subject of this forum. Best wishes from Oz.
  19. Yes, you are quite correct. FYI I 'manipulated' the array of completed tasks so that the recursive routine would display the completed tasks correctly. I must admit that it took a while to get the 'manipulation' code to work correctly but I got there in the end. There were two key issues - firstly for completed tasks, as they may have only been sub-tasks, the highest-level primary key in the completed tasks array is not necessarily zero. So the first task was to save that highest-level value for possible subsequent use. The second issue, again arising from the fact that completed tasks may have been sub-tasks, was to identify tasks where there was no link to a higher-level task in the completed-tasks array, and in that case to substitute the saved value from the paragraph above. Once this was done, everything worked OK. There was nothing wrong with the 'display_completed_tasks' recursive function! Thanks again for your input and suggestions. Cheers, Necuima.
  20. Mmmm - I think that I can see what the issue is. When listing 'live' tasks, the initial array passed has all the tasks with no parents, i.e., all tasks with parent-id of zero. Thus when a lower-level task processing has been completed, the recursion 'pops-up' to the next element in the highest-level array. When I try and use this logic for completed tasks, the only array element that initially gets passed to the recursive routine is the first array element. The logic correctly 'pops back' to the higher level when a lower-level completed task has been listed, but as the initial array only had one element there is nothing for the recursive logic to process and thus the function finishes its processing. I will have to try and think of another way to list completed tasks. This was in the spirit of a 'review and pursue' challenge! Cheers, Necuima.
  21. Hi HartleySan, As always, thanks for getting back to me. I am trying to use the logic in view_tasks.php as per the book page 18-23 but adjusted to recursively list out tasks marked as completed rather than 'live' tasks (the 'live' tasks part of my script works just fine). The DB structure is as per page 9 except that I used 'DATETIME' instead of 'TIMESTAMP'. Thus I check for NULL rather than a zeroed TIMESTAMP. The problem that I am getting is that the recursive function does not 'pop out' at the end of processing a subordinate task array to go back to processing a higher-level task array. I have been looking at my code 'till I am blue in the face' but am obviously missing something - it should function exactly as per the logic in Larry's view_tasks.php script. Again, any advice will be most appreciated. Cheers from Oz.
  22. Hi, I am trying to use similar recursive logic to Larry's in chapter 1. I have modified my code to enable you to mark tasks as completed and that works just fine. Now I am trying to use the recursive approach to list out the completed tasks in the same manner as 'live' tasks get listed. I create a two-dimensional array of completed tasks and then try to use the recursive logic to list out those tasks. It works only partially in that, say, a completed task has a parent, then that prints out OK. But, the logic in the display_completed_tasks recursive function does not 'pop back up' to the next highest level after (correctly) printing out part of the array. Maybe it is because the key of the first array passed is not necessarily zero - you can see that I save the first key in the list_completed_tasks function. I have printed out the arrays and they look OK. Here's my code: function list_completed_tasks() { global $dbc, $completed_tasks; $first_time_through = TRUE; $qa = 'SELECT task_id, parent_id, task FROM tasks WHERE date_completed IS NOT NULL ORDER BY parent_id, date_added ASC'; $ra = mysqli_query($dbc, $qa); $completed_tasks = array(); // Initialize the storage array: while (list($task_id, $parent_id, $task) = mysqli_fetch_row($ra)) { // Add to the array: $completed_tasks[$parent_id][$task_id] = $task; if ($first_time_through) { $first_key = $parent_id; $first_time_through = FALSE; } } echo '<h3>Completed Tasks Array Details</h3><pre>' . print_r($completed_tasks, 1) . '</pre>'; // For debugging and general interest display_completed_tasks($completed_tasks[$first_key]); } // end list_completed_tasks function function display_completed_tasks($complete_tasks) { // note: the value passed is an array echo '<p>Coming into display_completed_tasks: <pre>' . print_r($complete_tasks, 1) . '</pre>'; global $completed_tasks; // Start an ordered list: echo '<ol>'; // Loop through each subarray: foreach ($complete_tasks as $task_id => $done) { // Display the item: echo <<<EOT <li><input type="checkbox" name="marked_tasks[$task_id]" value="$done" /> $done EOT; // Note that the above creates an array of task_ids, even if only one checkbox is selected // The array is later accessed through the super-global $_POST['marked_tasks'] // Check for subtasks: if (isset($completed_tasks[$task_id])) { // isset checks the variables from left to right // in this instance, the isset is looking to see if the current sub-array element's task_id // is a parent_id in the multi-dimensional array $completed_tasks // Call this function recursively: // echo '<p>About to call the function recursively - calling it with: <pre>' . print_r($completed_tasks[$task_id], 1) . '</pre>'; // For debugging and general interest display_completed_tasks($completed_tasks[$task_id]); // note that $completed_tasks[$task_id] is an array in its own right (a sub-array of $completed_tasks) } // Complete the list item: echo '</li>'; } // End of FOREACH loop. // Close the ordered list: echo '</ol>'; } // End of display_completed_tasks() function. Any advice will be appreciated and thank you in anticipation.
  23. Hi Quinn, If Larry hasn't been able to fix the access to the code, maybe I can help. I could maybe email it to you but then I'd need your email address. The best way is probably via a dropbox. Let me know if I can help. Cheers from Oz, Necuima.
  24. Hi, I found a jQuery plug-in that will do this - it is called ImageMapster. The following parameters worked for me: ... <script type="text/javascript" src="../jQuery/jquery.imagemapster.min.js"></script> ... <script type="text/JavaScript"> $(document).ready(function() { $('img').mapster({ scaleMap: 'true', fillColor: 'd4ecfb', fillOpacity: 0.3, clickNavigate: 'true' }); }); // end document ready function $(window).resize(function() { var duration = 10; var newWidth = $('#wrapper').width(); $('img').mapster('resize',newWidth,0,duration); }); // end window resize function </script> Where the imagemap is the only image in this example, i.e., it is jQuery-selectable via 'img'. Cheers from Oz.
  25. OK, thanks Hartley-san. I will investigate other approaches. If I find one that works for me I will post the solution. Cheers from Oz.
×
×
  • Create New...