Jump to content
Larry Ullman's Book Forums

banacan

Members
  • Posts

    48
  • Joined

  • Last visited

Everything posted by banacan

  1. I have the following in my .htaccess file: Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^home$ index.php [L] RewriteRule ^bf/([A-Za-z0-9-]+)$ /bf/index.php?content=$1 RewriteRule ^bf/([A_Za-z0-9]+)/([0-9-]+)$ /bf/index.php?content=$1&event_id=$2 RewriteRule ^bf/([A_Za-z0-9]+)/([0-9-]+)$ /bf/index.php?content=$1&article_id=$2 Note the rule (second from bottom) for Events, this works fine, but the bottom rule does not. What I mean is that the page does not receive the article_id variable. When testing the $_GET variable article_id, I get nothing. *However* if I should reverse the order of the bottom two rules then the News page receives the article_id variable, but the Events page no longer receives the event_id variable. I understood that Apache goes down the list of RewriteRule(s) and applies the rule when it finds a match, but continues going down the list to the end if there is no match. Why does this work for one but not both. Why does it not pass by the Event rule to get to the News rule which contains the correct variable placeholder? Example links for the above rules are as follows: http://mydomain.com/bf/events/27 or http://mydomain.com/bf/news/3 Any ideas why this is not working?
  2. I think I finally have it figured out. I had forgotten that I had access to the pid value for each item - which for category pages is 0 - so for those whose pid = 0 I reset the $preface manually, the rest I kept as before. Here is my final code for those who are interested: // Funtion for displaying links. // Receives one argument: an array. function make_list ($parent, $preface = '') { // Need the main pages array: global $links; // Start an unordered list: echo '<ul class="sf-menu sf-vertical">'; // Loop through each subarray: foreach ($parent as $pid=>$item) { // Display the list item: ?> <li class="sf-hover"><a href="<?php echo $basedir . "/" . $preface . $item['link'] . "/" ?>"> <?php echo $item['nav']; ?></a><?php // Check for subpages: if (isset($links[$pid])) { // Call this function: make_list($links[$pid], ($preface .= $item['link'] . "/") ); // lop off last element of $preface array or reset it $length = strlen($preface); $pos = strrpos($preface,'/', -2); $slength = ($length - 1) - $pos; $item['pid'] == 0 ? $preface = '' : $preface = substr($preface, 0, -$slength); } // Complete the list item: echo '</li>'; } // End of FOREACH loop. // Close the unordered list: echo '</ul>'; } // end of make_list() function // Initialize the storage array: $links = array(); while (list($page_id, $pid, $nav_name, $link_name ) = mysql_fetch_array($pageList, MYSQL_BOTH)) { // Add to the array: $links[$pid][$page_id] = array('pid'=>$pid, 'nav'=>$nav_name,'link'=>$link_name); } Here is the resulting nav menu: Mouldings - link path is: /mouldings/ Historical - link path is: /mouldings/historical-mouldings/ Colonial - link path is: /mouldings/historical-mouldings/colonial-style-mouldings/ Craftsman - link path is: /mouldings/historical-mouldings/craftsman-style-mouldings/ Federal - link path is: /mouldings/historical-mouldings/federal-style-mouldings/ Georgian & Wren - link path is: /mouldings/historical-mouldings/georgian-and-wren/ Georgian - link path is: /mouldings/historical-mouldings/georgian-and-wren/georgian-style-mouldings/ Wren - link path is: /mouldings/historical-mouldings/georgian-and-wren/wren-style-mouldings/ Victorian - link path is: /mouldings/historical-mouldings/victorian-style-mouldings/ Stock - link path is: /mouldings/stock-mouldings/ Custom - link path is: /mouldings/custom-mouldings/ News - link path is: /news/ Industry - link path is: /news/industry-news/ Gallery - link path is: /gallery/ Thank you Larry for your help, I'm sure I wouldn't have gotten this figured out without it. And thank you also for the fine book that provided me with the initial script which has made this possible. This was a major accomplishment for me because it was vital for a dynamic navigation menu which works with my .htaccess file. I sure do value your books and this forum where you are always so generously giving of your time. Best, Brett
  3. Hi Larry, I'm very very close now thanks to your suggestion. Here is what I currently have: // Funtion for displaying links. // Receives one argument: an array. function make_list ($parent, $preface = '') { // Need the main pages array: global $links; // Start an unordered list: echo '<ul class="sf-menu sf-vertical">'; // Loop through each subarray: foreach ($parent as $pid=>$item) { // Display the list item: ?> <li class="sf-hover"><a href="<?php echo $basedir . "/" . $preface . $item['link'] . "/" ?>"> <?php echo $item['nav']; ?></a><?php // Check for subpages: if (isset($links[$pid])) { // Call this function: make_list($links[$pid], ($preface .= $item['link'] . "/") ); // lop off last element of $preface array $length = strlen($preface); $pos = strrpos($preface,'/', -2); $slength = ($length - 1) - $pos; $preface = substr($preface, 0, -$slength); } // Complete the list item: echo '</li>'; } // End of FOREACH loop. // Close the unordered list: echo '</ul>'; } // end of make_list() function // Initialize the storage array: $links = array(); while (list($page_id, $pid, $nav_name, $link_name ) = mysql_fetch_array($pageList, MYSQL_BOTH)) { // Add to the array: $links[$pid][$page_id] = array('pid'=>$pid, 'nav'=>$nav_name,'link'=>$link_name); } Here is the nav menu output: Mouldings - link path is: /mouldings/ Historical - link path is: /mouldings/historical-mouldings/ Colonial - link path is: /mouldings/historical-mouldings/colonial-style-mouldings/ Craftsman - link path is: /mouldings/historical-mouldings/craftsman-style-mouldings/ Federal - link path is: /mouldings/historical-mouldings/federal-style-mouldings/ Georgian & Wren - link path is: /mouldings/historical-mouldings/georgian-and-wren/ Georgian - link path is: /mouldings/historical-mouldings/georgian-and-wren/georgian-style-mouldings/ Wren - link path is: /mouldings/historical-mouldings/georgian-and-wren/wren-style-mouldings/ Victorian - link path is: /mouldings/historical-mouldings/victorian-style-mouldings/ Stock - link path is: /mouldings/stock-mouldings/ Custom - link path is: /mouldings/custom-mouldings/ News - link path is: /mnews/ Industry - link path is: /mnews/industry-news/ Gallery - link path is: /mgallery/ As you can see, the links are all correct until News and Gallery where there is a stray "m" mucking things up. These are base categories like Mouldings, but because I had to subtract 1 from $length to have the deeper links display correctly, it leaves the stray "m" (from Mouldings) in front of News and Gallery. Here is what happens if I don't subtract 1 from $length: Mouldings - link path is: /mouldings/ Historical - link path is: /mouldings/historical-mouldings/ Colonial - link path is: /mouldings/historical-mouldings/colonial-style-mouldings/ Craftsman - link path is: /mouldings/historical-mouldings/craftsman-style-mouldings/ Federal - link path is: /mouldings/historical-mouldings/federal-style-mouldings/ Georgian & Wren - link path is: /mouldings/historical-mouldings/georgian-and-wren/ Georgian - link path is: /mouldings/historical-mouldings/georgian-and-wren/georgian-style-mouldings/ Wren - link path is: /mouldings/historical-mouldings/georgian-and-wren/wren-style-mouldings/ Victorian - link path is: /mouldings/historical-mouldingsvictorian-style-mouldings/ Stock - link path is: /mouldingsstock-mouldings/ Custom - link path is: /mouldingscustom-mouldings/ News - link path is: /news/ Industry - link path is: /news/industry-news/ Gallery - link path is: /gallery/ You will see that the "/" is missing between historical-mouldings and victorian-style-mouldings, as well as mouldings and stock-mouldings, and mouldings and custom-mouldings. Now however, News and Gallery are correct. Do you have any ideas how to solve this? Thanks for your continued help.
  4. Hey Larry, Thanks for your reply, I totally understand about being behind on work, I too am overloaded at the moment which is why I'm so late in replying to you. It seems to me, if I understand what you are recommending, lopping off the last element of the array will work if each nested item is only one level away. But what happens if one nav link is 4 levels deep and the very next nav link is only 1 level deep? I'd only be lopping off to the third level which would make the hierarchy incorrect and the link wrong. Does that make sense? So I'm wondering, would there be a way to assign the depth level to each nav link and to the current depth level of the preface so that the array string could be cut back the right number of levels based on each nav link level? Could that work? Thanks, Brett
  5. Well that works great. Here's what I have: // Create the error handler. function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) { global $debug, $contact_email; // Don't display errors found if $findme is in $e_file $findme = '/calendar/'; $found = strpos($e_file, $findme); if ($found === false) { // Build the error message. $message = "An error occurred in script '$e_file' on line $e_line: \n<br />$e_message\n<br />"; //define timezone ini_set('date.timezone', 'America/Chicago'); // Add the date and time. $message .= "Date/Time: " . date('n-j-Y H:i:s') . "\n<br />"; // Append $e_vars to the $message. $message .= "<pre>" . print_r ($e_vars, 1) . "</pre>\n<br />"; if ($debug) { // Show the error. echo '<p class="error">' . $message . '</p>'; } else { // Log the error: error_log ($message, 1, $contact_email); // Send email. // Only print an error message if the error isn't a notice or strict. if ( ($e_number != E_NOTICE) && ($e_number < 2048)) { echo '<p class="error">A system error occurred. We apologize for the inconvenience.</p>'; } } // End of $debug IF. } // End of $found IF. } // End of my_error_handler() definition. I tested it to make sure that only those messages which are generated by a file with "/calendar/" in the string are excluded. Done. Thanks for your suggestion.
  6. Hey Jonathan, I checked through the 133 error message emails and there are many different files responsible for the errors. However, the calendar script is all contained in one sub-directory, so do you think there is a way to exclude any errors created by files within a certain directory? Thanks for helping.
  7. Thanks for the suggestion Jonathan. Unfortunately the client wants to have a short list of events in the sidebar of every page, so that work-around won't do. Thanks for responding though.
  8. I have a site that uses config.inc.php, script 2.1 which has the error handler, my_error_handler. It has worked beautifully for me on many sites over the years but now I have a problem. My client has asked me to use a calendar script on the site, the script is EasyPHPCalendar. The problem is this script creates so many errors that my email box fills up - it causes 133 email error messages to be sent each time a page is loaded. Most of the errors are "undefined variables" or "use of undefined constant", there are also "undefined index" and "constant already defined" errors. My question is how can I continue to use my_error_handler on this site without generating this plethora of errors? Right now I have commented out set_error_handler('my_error_handler') to avoid this problem. The server php.ini file sets the error reporting to E_ALL & ~E_NOTICE, the calendar script also has this: error_reporting(E_ALL ^ E_NOTICE); Why am I getting these notices and how can I adjust the config.inc.php script to prevent this? Many thanks.
  9. Hey Larry, I know you are busy and I also know that you give your time out of the goodness of your heart, so I want to thank you for spending a little of that valuable time on me. Warm regards, Brett
  10. Hi Larry, I'm still struggling to figure out how to reset $preface and I'm hoping you can provide some guidance. As I said in an earlier post, $preface resets itself when moving up to the parent level but it does not reset itself at the sibling level. It seems to me what I need to do is find the $key=>$value pair where the $key = the current $pid, then locate that $value in the $preface string so I can use substr() and stripos() to replace $preface. So my question is how do I search - within the foreach loop - for the $key=>$value pair where the $key = the current $pid?
  11. Larry, Thanks, I would appreciate any suggestions you might be able to offer.
  12. Well, I've figured out how to append the parents to the child to make the links correct. EXCEPT, as you said, I haven't been able to figure out how to get it to reset. Anyway, here is my modified code that at least creates the full path - for one branch of the tree: // Funtion for displaying list. // Receives one argument: an array. function make_list ($parent, $preface = '') { // Need the main pages array: global $links; // Start an unordered list: echo '<ul class="sf-menu sf-vertical">'; // Loop through each subarray: foreach ($parent as $pid=>$item) { // Display the list item: ?> <li class="sf-hover"><a href="<?php echo $basedir . "/" . $preface . $item['link'] . "/" ?>"> <?php echo $item['nav']; // Check for subpages: if (isset($links[$pid])) { // Call this function: make_list($links[$pid], ($preface .= $item['link'] . "/") ); } // Complete the list item: echo '</li>'; } // End of FOREACH loop. // Close the unordered list: echo '</ul>'; } // end of make_list() function Mouldings Historical Colonial Craftsman Federal Georgian & Wren Georgian Wren Victorian Stock Custom News Industry Gallery So from the structure shown above, the link for Wren is: http://www.whatever....tyle-mouldings/ Great, but the very next link in the list is Victorian and that link is: http://www.whatever....tyle-mouldings/ but it should be: http://www.whatever....tyle-mouldings/ but it's not, because I don't know how to reset the preface. To give you a little more info on what is being produced by this code, the link for Stock is: http://www.whatever....tock-mouldings/ it should be: http://www.whatever....tock-mouldings/ Preface seems to reset itself on links above itself, but not adjacent to itself, which is why the News link is: http://www.whatever....mouldings/news/ but should be: http://www.whatever.com/news/ news is adjacent to mouldings and so is gallery - all three are at the same nesting level. One last link to show you is for Gallery: http://www.whatever....s/news/gallery/ Here you can see how all previous adjacent links are added to the path, though they shouldn't be. Anyway, I hope this gives you some ideas on how this can be corrected and you might have a suggestion for me. Thanks
  13. Hi Larry, I've been able to get the parent link added to the path of the current link, but I still haven't figured out how to append the new parent link onto the previous "preface" and continue that process to the last child. Also, it's unclear to me how the recursion process works - I hope I can describe what I mean because I'm sure it makes very big difference. During recursion, does the "path" begin at the root level and proceed down every child to the end, creating a complete map for each child, or does it map only from the parent node for each? I'm assuming, based on your previous post about resetting, that it only maps from the parent node. Here is what I have right now that is working - sort of: // Funtion for displaying list. // Receives one argument: an array. function make_list ($parent, $preface = '') { // Need the main pages array: global $links; // Start an unordered list: echo '<ul class="sf-menu sf-vertical">'; // Loop through each subarray: foreach ($parent as $pid=>$item) { // Display the list item: ?> <li class="sf-hover"><a href="<?php echo $basedir . "/" . $preface . "/" . $item['link'] ?>/"> <?php echo $item['nav']; // Check for subpages: if (isset($links[$pid])) { // Call this function: make_list($links[$pid], $item['link']); } // Complete the list item: echo '</li>'; } // End of FOREACH loop. // Close the unordered list: echo '</ul>'; } // end of make_list() function ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Test nested navigation</title> </head> <body> <?php // Initialize the storage array: $links = array(); while (list($page_id, $pid, $nav_name, $link_name ) = mysql_fetch_array($pageList, MYSQL_NUM)) { // Add to the array: $links[$pid][$page_id] = array('pid'=>$pid, 'nav'=>$nav_name,'link'=>$link_name); } // For debugging: echo '<pre>' . print_r($links,1) . '</pre>'; // Send the first array element // to the make_list() function: make_list($links[0]); ?> </body> Thanks for your help.
  14. Hi Larry, I'm sorry for the long delay in responding to your last post, I was sick for a week and when I got back to work I had a big backlog of work and looming deadlines. I have tried a couple of things so far but nothing is working. I tried adding the second argument to the function, but when I called the function with $nav_name as the value of the second parameter, nothing at all appeared - there was no value. I thought it might help for you to see the nesting structure so you can see what I'm trying to accomplish: Array ( [0] => Array ( [34] => Array ( [pid] => 0 [nav] => Mouldings [link] => mouldings ) [35] => Array ( [pid] => 0 [nav] => News [link] => news ) [57] => Array ( [pid] => 0 [nav] => Gallery [link] => gallery ) ) [34] => Array ( [36] => Array ( [pid] => 34 [nav] => Historical [link] => historical-mouldings ) [37] => Array ( [pid] => 34 [nav] => Stock [link] => stock-mouldings ) [46] => Array ( [pid] => 34 [nav] => Custom [link] => custom-mouldings ) ) [35] => Array ( [44] => Array ( [pid] => 35 [nav] => Industry [link] => industry-news ) ) [36] => Array ( [45] => Array ( [pid] => 36 [nav] => Colonial [link] => colonial-style-mouldings ) [38] => Array ( [pid] => 36 [nav] => Craftsman [link] => craftsman-style-mouldings ) [39] => Array ( [pid] => 36 [nav] => Federal [link] => federal-style-mouldings ) [47] => Array ( [pid] => 36 [nav] => Georgian & Wren [link] => georgian-and-wren ) [59] => Array ( [pid] => 36 [nav] => Victorian [link] => victorian-style-mouldings ) ) [47] => Array ( [58] => Array ( [pid] => 47 [nav] => Georgian [link] => georgian-style-mouldings ) [48] => Array ( [pid] => 47 [nav] => Wren [link] => wren-style-mouldings ) ) ) Mouldings Historical Colonial Craftsman Federal Georgian & Wren Georgian Wren Victorian Stock Custom News Industry Gallery This is not all of the structure but it will show you the level of nesting involved. Your continued help is appreciated.
  15. The recursion function "walks the tree", iteration by iteration, mapping the entire tree. But as it does so, it replaces the variable value during each iteration. So how would the "preface" be created? It seems to me that what I need is a second function that can walk the tree in the opposite direction creating an array of all link_names related by pid and page_id up to 0. As you have probably figured out, I'm trying to create a dynamic menu for use with my .htaccess file. Using your modularized web site approach, I have the home page at the site root, then I have sub-directories (what I call category directories) which contain modularized index pages (all category pages have a pid value of 0). All pages below each category page can be further nested by making the parent page (page_id) it is descended from the pid. Though the descendant category pages are really just the index page with the content being replaced, I need to show the hierarchical relationship to match the RewriteRule in my .htaccess file. This is an issue that must be common, since all frameworks use this method. Do you know how they have solved this problem? I assume some form of recursion is necessary, since the level of depth is unknown. Thanks for your continued help.
  16. If I understand your question, try this: RewriteRule ^test/([0-9]+)/([0-9]+)$ test.php?s=$1&p=$2
  17. Hi Larry, I have another question, is there a way to show the "path" of sub-navigation items within this script? Say the main category is Fresh Fruits & Vegetables, a sub-category would be Fruits, and the item would be Apples. I would like to have the hierarchy part of the <li> element for linking purposes. So something like: fresh-fruits-and-vegetables/fruits/apples/ In the multidimensional array structure the "categories" are represented by the pid, so I would need to use the associated link_name for each level or iteration. Can this be done? Many thanks, Brett
  18. As I suspected, the problem was with escaping single and double quotes. Instead of trying to find my way through that labyrinth, I just combined HTML and code using the concatenator ".", now all is well. Thanks Larry.
  19. Hi Larry, Thanks for the reply. I made those changes and the structure is correct (I see the sub-array with 'link' and 'nav') but I'm having difficulty with the output. If I have: echo "<li class=\"sf_hover\">$nav_name"; I see the structure (with the debugging uncommented) though there is nothing but an empty ul li. If I have: echo "<li class=\"sf_hover\">$item['nav']"; I see nothing, just a blank page. What is happening?
  20. I'm using a modification of script 1.3 to create a nested navigation menu. So far I've got the structure working great, the question I have is how do I add another field to the list() array - or in my case the link() array. What I have now is the navigation name showing in the structure, but I need the value from another field for the link. Here is what I have: // Funtion for displaying list. // Receives one argument: an array. function make_list ($parent) { // Need the main pages array: global $links; // Start an unordered list: echo '<ul class="sf-menu sf-vertical">'; // Loop through each subarray: foreach ($parent as $pid => $nav_name) { // Display the list item: echo "<li class=\"sfHover\"><a href=\"$link_name\">$nav_name</a>"; // Check for subpages: if (isset($links[$pid])) { // Call this function: make_list($links[$pid]); } // Complete the list item: echo '</li>'; } // End of FOREACH loop. // Close the unordered list: echo '</ul>'; } // end of make_list() function ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Test nested navigation</title> </head> <body> <?php // Initialize the storage array: $links = array(); while (list($page_id, $pid, $nav_name, $link_name ) = mysql_fetch_array($pageList, MYSQL_NUM)) { // Add to the array: $links[$pid][$page_id] = $nav_name; } // For debugging: echo '<pre>' . print_r($links,1) . '</pre>'; // Send the first array element // to the make_list() function: make_list($links[$start]); As you can see, I've added $link_name to the while(list()) but I can't understand how to get $link_name added to the array which contains the nested navigation items. You can also see how I have added $link_name to the <a> element in the <li> but when I test the script I only get <a href="">whatever</a>. Here is my SQL: mysql_select_db($database_siteuser, $siteuser); $query_pageList = "SELECT page_id, pid, nav_name, link_name, ordr FROM webtext WHERE page_id != 0 AND navInclude = 'y' OR sidebar_disp = 'y' ORDER BY pid, ordr"; $pageList = mysql_query($query_pageList, $siteuser) or die(mysql_error()); $row_pageList = mysql_fetch_assoc($pageList); Any help would be appreciated.
  21. Larry, Yeah, it probably would be simpler to make this all one table - though I will have a bit of housekeeping to do. I guess I'll get to work combining these tables, changing queries, etc. Thanks for providing perspective.
  22. Hi Larry, Thanks for your reply. Basically I'm creating something like you have in chapter 2, Modularizing a Web Site, but I'm getting all of the content for each page from a database (two tables). One table contains all page data, like Page Title, Meta Description, Navigation Name, Link Name, Navigation Title, PID (parent ID for sub-navigation), Order (navigation order), etc., the other table contains all of the page content, like Copy, Headings, Images, etc. As I said in my previous post, I originally had this as a two-step process. The first step was to provide the page data through one page/form, then the next step, on a different page/form, the page content would be entered and linked to the correct page data record by storing it's page_id in a field called page_id. Then using a left join in my query, the content would be assembled on the web page. Now I want to eliminate one step in the process and have one page/form that inputs data into two tables. But as I say, the first table, "w_page", contains the page data, and the page_id in that table is auto-increment. The other table, "webtext", contains the page content, and its page_id field was set by the user. So I'm trying to figure out how to set the page_id value in both tables so I can keep them linked. I like having the page_id set by auto-increment because the database will insure that the value is always unique, but it leaves me with the problem of getting that value into the webtext table at the same time. I hope this gives you a better idea of what I'm trying to accomplish. Now I'll list the table structure for your information. Table w_page page_id - key field (auto-increment) int(10) page_name - varchar nav_name - varchar link_name - varchar title - varchar navInclude - enum (y/n) subnavInclude - enum (y/n) pid - int(2) page_title - varchar meta_desc - varchar order - int(2) webtext copy_id - key field (auto-increment) int(10) headline - varchar deck - varchar subhead - varchar body_copy - text image - varchar caption - varchar page_id - int(10) There are many more field in the webtext table but they are identical like subheads 1-4, body_copy 1-4, etc. but this gives you the idea. Any suggestions you might have I would appreciate hearing. Thanks for your help Larry. I hope you and your family are well. Best, Brett
  23. I've created a page with one form and two INSERT commands to add content to two tables. They are linked by a common field, page_id. In the past there were two separate pages, one for each section to INSERT the content. The first page set the page_id using AUTO-INCREMENT, then at the next page, the user would select the page to link and the page_id would be inserted into that table. Now I want to make one page that will INSERT a unique value into the common field of both tables at once so they can be linked. I realize that the common field cannot be the AUTO-INCREMENT field from the one table as before, so my question is, what is the best way to go about this. How do I generate a unique value to input into each table? Should I QUERY the primary table, find the highest number in that field and add 1? Any suggestions would be helpful.
×
×
  • Create New...