Jump to content

son

Members
  • Content Count

    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. son

    Nav with several levels

    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. Got the answer! Gosh, recently my brain has really gone for a walk... The following does the trick: $galleryCheckQuery = "SELECT imgID FROM table1 WHERE catID = $catID OR catID IN (SELECT catID FROM table1 WHERE parent = $catID)"; Son
  13. I get data from db that holds info about category parents and sub-categories as $galleryCheckQuery = "SELECT imgID FROM table1 WHERE catID = $catID OR catID = (SELECT catID FROM table1 WHERE parent = $catID)"; Now I have the issue that this is not working when there are several sub-categories... What would be a good solution to this? Son
  14. 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
  15. I have done it like this now: function renderTree($parent = 0, $subCounter = 0){ global $categoryNames; global $childrenTree; if($parent != 0) { echo "<option value='" . $parent . "' style='padding-left:" . $subCounter . "px;'>", $categoryNames[$parent], "</option>\n"; $subCounter = $subCounter + 5; } $children = $childrenTree[$parent]; if(count($children) > 0) { //If node has children foreach($children as $child) renderTree($child, $subCounter); } }echo "<select>\n";renderTree(); //This renders the hierarchical tree echo "</select>\n"; which does is slightly different to what you suggested. It works. Do you think this is ok like this or are there any disadvantages to my approach? I mean it contains the key elements you suggested, only that I added a parameter to indicate padding-left for each child's level... Son
  16. I cannot believe this... I simply did not see this. Taking it out works well and does exactly what I anticipated. Gosh, sometimes I think I really need a pair of glasses;-) Thanks for this. Just one more question: Is there a way to indent each level a bit further to right? How having them all starting at same level I realise that the drawback is that it is not very easy to distinguish levels now... Son
  17. I get data from db as while (list($catID, $catName, $catParent) = mysqli_fetch_array($rs, MYSQLI_BOTH)) { $categoryNames[(string)$catID] = $catName; $catParent = (string)$catParent; if(!array_key_exists($catParent, $childrenTree)) $childrenTree[$catParent] = array(); $childrenTree[$catParent][] = (string)$catID; } and want to display data as select drop down with each level a bit further indented. When I simply displayed as function renderTree($parent = "0"){ global $categoryNames; global $childrenTree; if($parent != "0") echo "<li> ", $categoryNames[$parent], "\n"; $children = $childrenTree[$parent]; if(count($children) > 0) { //If node has children echo "<ul>\n"; foreach($children as $child) renderTree($child); echo "</ul>\n"; } if($parent != "0") echo "</li>\n"; } renderTree(); //This renders the hierarchical tree it worked well, but now to try with select cannot get it working. Currently have: function renderTree2($parent = "0"){ global $categoryNames; global $childrenTree; if($parent != "0") echo "<option>", $parent . $categoryNames[$parent], "</option>\n"; $children = $childrenTree[$parent]; if(count($children) > 0) { //If node has children echo "<option>\n"; foreach($children as $child) renderTree($child); echo "</option>\n"; } }echo "<select>";renderTree2(); //This renders the hierarchical tree echo "</select>"; It outputs the wrong code: <option><li> main page<ul><li> sub page<ul><li> Sub Sub</li></ul></li></ul></li></option></select> Any ideas where I am going wrong? Son
  18. What do i need to center images in fadeslideshow.js? Cannot get it working... Son
  19. son

    Valid file name?

    System has no issues with it, but as it will result in web page being displayed online I only wondered... Thanks,Son
  20. I had an issue with a slide-out side navigation as the sub-level was hidden behind a slideshow which plays next to it. I did apply a higher z-index to nav, but still would not work. Realised in end that I had to apply the high z-index to#nav liand not#navand got it working fine:-) Hope this might be helpful for someone else... Son
  21. son

    Valid file name?

    Would it be valid to have a file ashyphen-_-rightNextToUnderscore.htm? Not that I think this is pretty, but could happen in system I am currently working on;-) Son
  22. son

    Loop help needed

    It did not get any data. Found the issue. The data from the three columns were mixed type, but I used mysqli_fetch_array($rs, MYSQL_ASSOC) I did replace this now with mysqli_fetch_array($rs, MYSQLI_BOTH) which gets the data fine and the tree is displayed. Now I have to figure out how to change the whole thing to a select drop down as tree much longer than I thought... Many thanks for pointers,Son
  23. son

    Loop help needed

    No result whatsoever, empty screen. I run the query in phpMyAdmin to make sure there is no issue and it was running in there ok... Son
  24. son

    Loop help needed

    I cannot get this working. The problem lies aleady in establishing the array data. I have now: $rq = 'SELECT haloID, halo, haloParent FROM haloTable';$rs = mysqli_query($dbc, $rq); $childrenTree = array(); //store an array of children for each parent $categoryNames = array(); //store category name for each id //fill $childrenTree and $categoryNames from database while (list($haloID, $halo, $haloParent) = mysqli_fetch_array($rs, MYSQL_ASSOC)) { $categoryNames[(string)$haloID] = $halo; $haloParent = (string)$haloParent; if(!array_key_exists($haloParent, $childrenTree)) $childrenTree[$haloParent] = array(); $childrenTree[$haloParent][] = (string)$haloID; }function renderTree($parent = "0"){ global $categoryNames; global $childrenTree; if($parent != "0") echo "<li> ", $categoryNames[$parent], "\n"; $children = $childrenTree[$parent]; if(count($children) > 0){ //If node has children echo "<ul>\n"; foreach($children as $child) renderTree($child); echo "</ul>\n"; } if($parent != "0") echo "</li>\n";}renderTree(); //This renders the hierarchical tree
×
×
  • Create New...