Jump to content

son

Members
  • Posts

    1,024
  • Joined

  • Last visited

Everything posted by son

  1. son

    xml in php file

    In a php file I tried to generate xml and hoped thatheader('Content-Type: text/xml');at top would just do this... It doesn't. I can see the xml correctly formed in source code, but on page only the standard subscribe to feed message shows without the items from database... Is it not possible to use php file for xml? Thanks,Son
  2. I have a top nav where you only see items from next level if you hover over li item of main list. The css is: #navItems {margin:25px 0;}#navItems ul {float:right; margin-left:15px;}#navItems ul li {float:left; position:relative;}#navItems ul li a {display:block;padding:3px;}#navItems li ul {display: none; margin:0;}#navItems li:hover ul {position: absolute;display:inline; left:0;}#navItems ul li ul li {width:340px;} Initially I did not have:#navItems ul li ul li {width:340px;}but I added the width as text broke down in several rows if main list item narrower than sub-item. Now, I find that sometimes 340px does not work well and I would like to have the sub-items' width adjust to the relevant text lenght (that could be less, equal or more than main item. How can I achieve this? Also, is there a way to have more sub-levels with same hovering over parent item to show sub-items? I added another sub-level (level 3), but could not make it work... Son
  3. On query string is fine. It is only for language swap anyway, lang is then stored in session... Thanks a lot, S
  4. I use mod-rewrite as:RewriteRule ^([A-Za-z0-9_-]+)$ webs.php?id=$1 [NC] It rewrites all URLs ok. However, I need to insert a language option (Italian and English) and this does not work due to rewrite rule. Has anyone experience and let me know how to change my rewrite rule? Thanks,Son
  5. I did set $childrenTree = array(); just before loop as suggested and had then also added a check if $parent is set in function as if(isset($parent) && $parent != 0) { I still get the same 'Undefined index: ' for all the entries that are not parents themselves... The one that is a parent to two entries is fine... Son
  6. But this is where the my problem is to understand. I only want to initialise when there are children as if(!array_key_exists($catParent, $childrenTree)) $childrenTree[$catParent] = array(); $childrenTree[$catParent][] = (string)$catID; However, going through all the thrown error codes after 'Undefined variable: childrenTree' it also repeatetly complains 'Undefined index'. Checking all those indexes in detail I can clearly see that those are all the ones without children. The one category with children does not come up in error code. Also, that it works on other page exactly like it is totally confuses me... Any ideas where else I could check? Son
  7. In my desperation I have tried already above this bit of code: $childrenTree = 0; $childrenTree = ''; $childrenTree = FALSE;The first about undefined variable indeed gone, but still 'The second argument should be either an array or an object'. In addition, I did not do anything else on other pages where it is working... Could it be that other variable infringe with the code? I do not have another $childrenTree, but maybe another one is causing this? Son
  8. I use the following data and function successfully on another page that has lots of other stuff going on (and a test page with only this bit): while (list($catID, $catNameSelect, $catParentSelect) = mysqli_fetch_array($catResult, MYSQLI_BOTH)) { $categoryNR[(string)$catID] = $catID; $categoryNames[(string)$catID] = $catNameSelect; $catParent = (string)$catParentSelect; if(!array_key_exists($catParent, $childrenTree)) $childrenTree[$catParent] = array(); $childrenTree[$catParent][] = (string)$catID; }function renderTree($parent = 0, $subCounter = 0){global $cid;global $categoryNR; global $categoryNames; global $childrenTree; if($parent != 0) { echo "<option value=\"webster.php?cid=" . $categoryNR[$parent] . "\""; echo " style=\"padding-left:" . $subCounter . "px;\">", $categoryNames[$parent], "</option>\n"; $subCounter = $subCounter + 10; } $children = $childrenTree[$parent]; if(count($children) > 0) { //If node has children foreach($children as $child) renderTree($child, $subCounter); } }renderTree(); //This renders the hierarchical tree However, on the relevant page it shows drop down ok, but when you look in code you can see that there is an issue...Undefined variable: childrenTreearray_key_exists() [<a href=function.array-key-exists'>function.array-key-exists</a>]: The second argument should be either an array or an object I do not get this. It is working fine on other page/s with same query and the lot. Why is it saying that childrenTree is not defined in this case? Where could I look? Thanks,Son
  9. Will check it carefully again. ThanksSon
  10. son

    Web Address validation

    Thanks. Will look into this... Son
  11. son

    Web Address validation

    I have a form field where user enter a web address. I do some preg_replace before this gets inserted into db as: $webAddress = $_POST['webAddress'];$webAddress = preg_replace('/\s[\s]+/','-',$webAddress); // Strip off multiple spaces$webAddress = preg_replace('/[\s]+/','-',$webAddress); // Strip off spaces $webAddress = preg_replace('/^[\-_]+/','',$webAddress); // Strip off the starting hyphens/underscores$webAddress = preg_replace('/[\-_]+$/','',$webAddress); // // Strip off the ending hyphens/underscores Now I wonder if that is actually sufficient? And I worry about people entering/not entering the 'http://' and 'www' bit. I refrained from checking and automatically inserting as some web addresses do not have 'www' and other users might want to include a link to an ftp server. What is a good practice? Thanks,Son
  12. I have been working with this function to display data from db in select element. All working well, but now struggling with a nice touch to include the <optgroup /> element for items of same nav group. The code is: function renderTree($parent = 0, $subCounter = 0, $navInit = 0){global $pid;global $categoryNR;global $categoryNav; global $categoryNames; global $childrenTree; if($parent != 0) { $catNavCounter = $categoryNav[$parent]; if ($catNavCounter != $navInit) { echo "<optgroup label=\"test\">"; $navInit = $navInit++; } echo "<option value=\"page.php?pid=" . $categoryNR[$parent] . "\""; if ((isset($pid)) && ($pid == $categoryNR[$parent])) { echo " selected=\"selected\" "; } echo " style=\"padding-left:" . $subCounter . "px;\">", $categoryNames[$parent] . " Navigation: " . $categoryNav[$parent] , "</option>\n"; $subCounter = $subCounter + 10;$catNavCounter = $categoryNav[$parent]; if ($catNavCounter != $navInit) { echo "</optgroup>"; } } $children = $childrenTree[$parent]; if(count($children) > 0) { //If node has children foreach($children as $child) renderTree($child, $subCounter); } }renderTree(); //This renders the hierarchical tree} Unfortunately my code creates an <optgroup /> element for each item... $categoryNav[$parent] shows fine in <option /> text, so issue is not related to data in array... Where am I going wrong? Son
×
×
  • Create New...