muuucho Posted February 26, 2012 Share Posted February 26, 2012 Edit. About script 1.3 view_tasks.php Question1: How can the code below see if the task has a subtask by looking at the task's task_id? Question2: Is there a way to determine if the task's parent_id=0 inside the foreach? (I want to add a link to each Main task) // Check for subtasks: if (isset($tasks[$task_id])) { // Call this function: make_list($tasks[$task_id]); } Link to comment Share on other sites More sharing options...
muuucho Posted February 29, 2012 Author Share Posted February 29, 2012 I think i've got question 1 after having read in the book again: isset ($tasks[$task_id]) means is there an array element in $tasks whose key is this task_id? Only Q2 is yet to be solved! Link to comment Share on other sites More sharing options...
Larry Posted February 29, 2012 Share Posted February 29, 2012 For question 1, yes, that's exactly correct. For question 2, off the top of my head, I believe you'd need to pass the parent ID value into the function in order to have access to that. Link to comment Share on other sites More sharing options...
mixa_ru Posted March 16, 2012 Share Posted March 16, 2012 Larry hello! I like your books very much! They are easy to read and understand. I'm also very much impressed with some ideas in your code. According with PHP5 Advanced book they are Parent_sort function together with usort and recursive Make_list functions. How do you know that? How do you get inspired with such an ideas? Books? Practice? Expirience? Can you recommend something to read extra? With best regards, Mikhail Link to comment Share on other sites More sharing options...
Larry Posted March 16, 2012 Share Posted March 16, 2012 Thanks for the nice words. I appreciate it. Mostly I get my ideas from experience, from problems I had to solve. What, specifically, are you looking for as a recommendation? Link to comment Share on other sites More sharing options...
mixa_ru Posted March 17, 2012 Share Posted March 17, 2012 Larry thanks for your qucik reply! Unfortunately I can not say exactly what I'm looking for.... It's all about some nice and cute ideas, algorithms, solutions and code snippets. For example: now I'm working with product catalog (add-delete-update/rename items, unlimited levels, tree structure etc.) and a couple of solutions from your PHP5 Advanced book were perfect for it! If I havn't read your book I'd probably use at list two tables with realtions and it would not be as easy as idea from your book: one table is enough together with sorting function and recursive function. And something like this. Or may be vice versa: if I use two tables (one for nodes/parents another table for children and relations in-between) may be it would be easier,better and more flexible? What do you think? Best Regards, Mikhail Link to comment Share on other sites More sharing options...
Antonio Conte Posted March 19, 2012 Share Posted March 19, 2012 Recursion is a very specific programming solution. In most cases regular loops will do the job perfectly, but in those special cases the power of recursion cannot be beaten. If you read up on recursive programming, you will see there's even rules for how to write recursive algorithms. If you are interested in the more advanced asPects of programming, you should read up on big O-analysis, data structures and object-oriented programming. How does functions like mysql_fetch_array() works? Why is array_key_exsist a faster function than in_array in most cases? Getting a better understandment for how basic functionally works if often a good idea. Could you write a custom function that is faster than in_array()? Could you implement the iterator used in mysql_fetch_array() in your own code for easy array iterations? These are possible next steps. Link to comment Share on other sites More sharing options...
mixa_ru Posted March 19, 2012 Share Posted March 19, 2012 Hi Antonio! Thank you for your post! I will try to follow your ideas to deeply understand programming. Can you please recommend some books (I have already 3 PHP books of Larry)? What programming or algorithm book impressed you best of all? Thank you! Link to comment Share on other sites More sharing options...
Antonio Conte Posted March 19, 2012 Share Posted March 19, 2012 I don't really know what to suggest to you. Larry might have something to add. I would recommend you to learn how to use objects, learn a little about algorithms, and to just play with PHP. I tried a youtube-search, and looks like a good introduction to algorithms. It is not written in PHP, but it applies to PHP as well. Do not focus to much on math here. What's important is to have a basic understanding of how fast algorithms are when finding/sorting etc. I haven't looked trough more than one video, but it looks promising. This will give you an understanding on why you should use associative arrays in PHP (They are called hash maps in some other languages) and how to write fast code in general. This will give you a better understanding of how data is saved and manipulated inside a PHP array. (Read about PHP arrays in the manual) What's special with PHP arrays are that they can be used as Stacks, queues, hash maps, linked lists and general collections in. In many other languages, these are different data structures with different strengths and weaknesses. Understanding arrays are in other words VERY important in PHP. Link to comment Share on other sites More sharing options...
mixa_ru Posted March 20, 2012 Share Posted March 20, 2012 Hi Antonio! I started to watch videos, it's very easy to understand! Thanks for you and the author of these videos! Best regards, Mikhail Link to comment Share on other sites More sharing options...
Recommended Posts