PHP - Ul List With Nested Ul List (subcategories)
Hello there,
this is a really noob question, but I've no idea on how to make it work without making everything messy and crappy. I have one SQL table called categories, and another called subcategories. Inside the subcategories table there's a field named 'parent' that will link it to the correspondent category, so it should look something like this in html: Code: [Select] <ul> <li>Category <ul> <li>Subcategory</li> </ul> </li> </ul> Would you please give this poor guy a hand? =) Similar Tutorialshello. i have a list that is pulling info from a db but the sub levels are not showing correctly. basically there are titles that could be in any order then under each title there are lists that could be in any order then some of the lists might also have nested lists which could be in any oder. its not the full html yet but I'm stuck because it echoes out the titles fine but the links are not being listed under each title. all the links are being listed under the first title only. Code: [Select] $PCa = PageContent::find_by_pageContID($PCidA); foreach ($PCa as $PCas) { $title = $PCas->title; $link = $PCas->link; echo' <div class="arrowlistmenu">'; if (!empty($title)) { echo' <h3 class="menuheader expandable">'."{$title}".'</h3>'; } if (!empty($link)) { echo' <ul class="categoryitems"> <li><a href="#">'."{$link}".'</a></li> </ul>'; } echo'</div>'; } this is an example of the html. Code: [Select] <div class="NAV"> <h3>CAT TITLE</h3> <ul class="CAT ITEM"> <li><a href="#">LINK</a></li> </ul> <h3>CATT TITLE</h3> <ul class="CAT ITEM"> <li><a href="#">LINK</a></li> <li><a href="#" class="SUB CAT">NESTED LEVEL TITLE</a> <ul class="SUB CAT ITEM" style="margin-left: 15px"> <li><a href="#">LINK</a></li> </ul> </li> <li><a href="#">LINK</a></li> </ul> </div> thanks hello. i finally got my nested list working but its only go 2 levels. how do i make it unlimited levels ? this is a nested list Code: [Select] <ul> <li><a href="#">list</a></li> <li><a href="#" class="sub">sub title</a> <ul class="subcat" style="margin-left: 15px"> <li><a href="#">sub title</a></li> </ul> </li> </ul> this is not the actual code but this is how it works at the moment Code: [Select] <ul> if($Level == "list"){ <li><a href="#">list</a></li> }elseif($Level == "subList"){ <li><a href="#" class="sub">sub title</a> <ul class="subcat" style="margin-left: 15px"> <li><a href="#">sub title</a></li> </ul> </li> } </ul> Hi, In my mysql database i have a text input option, in the registration form and edit my details form i have a multiple select dropdown list, which user selects options to populate the text input box, which ultimately populates the text field in the mysql database. All works perfectly. The dropdownlist consists of 3 parts <optgroups> first is current selection (what is the usesr current selection)works fine, The second <optgroup> is existing words, what words we(the site) have given as options, and the third <optgroup> is the words that others have used. This is where im having a small problem. Because its a text field when i call the data from the database, it calls the entire text box as a single option in my select list.. I want to break the words in the text field (at the comma) and have them listed each one as an option in the select list. Example what i need: Words in text box:(my input allows the "comma") word1, word2, word3, word4, word5, word6, How i want them called/displayed: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> here's my code: $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $original_functionsexperience =doSelectSql($query,1); $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $functionsexperiencelist=doSelectSql($query); $funcexpList ="<select multiple=\"multiple\" onchange=\"setFunctionsexperience(this.options)\">"; foreach ($functionsexperiencelist as $functionsexperienceal) { $selected=""; if ($functionsexperienceals->allwords == $original_functionsexperience) $selected=' selected="selected"'; $allwords=$functionsexperienceal->allwords; $funcexpList .= "<optgroup label=\"Current selection\"> <option value=\"".$allwords."\" ".$selected." >".$allwords."</option> </optgroup> <optgroup label=\"Existing Words\"> <option value=\"existing1,\">existing1</option> <option value=\"existing2,\">existing2</option> <option value=\"existing3,\">existing3</option> <option value=\"existing4,\">existing4</option> <option value=\"existing5,\">existing5</option> <option value=\"existing6,\">existing6</option> </optgroup> <optgroup label=\"Others added\"> //heres problem <option value=\"".$allwordsgeneral."\">".$allwordsgeneral."</option> </optgroup>"; } $funcexpList.="</select>"; $output['FUNCEXPLIST']=$funcexpList; The result im getting for optgroup others added: word1, word2, word3, word4, word5, how can i get it like this: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> Hi , I have one question .. Can I split showing of content of dynamic list in 2 parts , when I echo list in code .. Code: [Select] <?php // Run a select query to get my letest 8 items // Connect to the MySQL database include "../connect_to_mysql.php"; $dynamicList = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 8"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamicList .= '<table width="100%" border="2" cellspacing="2" cellpadding="2"> <tr> <td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="2" /></a></td> <td width="83%" valign="top">' . $product_name . '<br /> $' . $price . '<br /> <a href="product.php?id=' . $id . '">View Product Details</a></td> </tr> </table>'; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> Code: [Select] <p><?php echo $dynamicList; ?><br /> </p> It works ok, and putting my files, everything works, but when I put 8 pictures with price and other details, it just show one image with details and another image below with details, and the third image below and so on .. Can I split dynamic list to show 4 images with details on the left side and 4 on the right side? Thank you in advance for help , if is possible Hi, I use the following code to create a select menu from an array of options stored in LISTS.php: include 'LISTS.php'; print('<select id="from" name="from">'); foreach ($langList as $lang) {printf('<option %s>%s</option>', ($from1 == $lang ? 'selected="selected"' : ''), $lang); } echo '</select>'; where LISTS.php includes the following: $langList = array(' ','English', 'French', 'German', 'Dutch', 'Spanish'); This works great, but now I want to do something similar with a checkbox list, where each checkbox has an associated 'onchange' javascript function and I'm getting pretty stuck. My checkbox list is of the following form: Code: [Select] <html> <ul style="height: 95px; overflow: auto; width: 200px; border: 1px solid #480091; list-style-type: none; margin: 0; padding: 0;"> <li id="li1b"><label for="chk1b"><input name="chk1b" id="chk1b" type="checkbox" onchange="function1('chk1b','li1b')">Option1</label></li> <li id="li2b"><label for="chk2b"><input name="chk2b" id="chk2b" type="checkbox" onchange="function1('chk2b','li2b')">Option2</label></li> //etc. </ul> </html> What I want to do is have 'Option1', 'Option2', etc. stored in an array in LISTS.php and have a PHP script that populates the checkbox list accordingly, in a similar manner to my select menu above. I can't work out how to get the ID of the next <li> and the next <input> in the list to go up by one each time, e.g. 'li1b' then 'li2b', 'li3b', etc. Could someone pls help me out? Thanks! Is there a way to take data that is listed like a,b,c,d,e and turn that into an unordered list? Basically, I'm going to have a list of schools that will be listed with comma separators. I'll print that data out in two places, one will be printed as it's in the database. The other I would like to echo as an unordered list. How hard would something like this be? I have a database with all my users. I need an empty list and when a user clicks a button "Add me to the list" they are added to the first position in the list Slots 1. Tom 2. 3. 4. 5. Later, Jerry wants to be added to the list. So this happens Slots 1. Jerry 2. Tom 3. 4. 5. More people join the list 1. Bob 2. John 3. Jerry 4. Tom 5. Tom gets upset clicks the same button to join the list again, and he's bumped back up to first place. Slots 1. Tom 2. Bob 3. John 4. Jerry 5. Is this possible? And is so, how would I go about getting started on such a thing? I've been using PHP for about a year and a half. Is it possible to get bittorrent peer list (IP list) via php, udp protocol ? txh! Hey, I'm having a issue with using a listbox.. Am I doing something wrong?? Heres my HTML: Code: [Select] <select style="height:100px;width:250px;" name="countries[]" multiple> <option value="US">United States</option> <option value="UK">United Kingdom</option> <option value="CA">Canada</option> <option value="AU">Australia</option> </select> and my PHP: $countries = $_POST['countries']; $countries = implode(' | ', $countries); I'm trying to set it up so I can insert the data as: US | UK | CA. But, when I submit the form, I get these errors: Quote Notice: Undefined index: countries in /Applications/MAMP/htdocs/mynewscript/admin/cp/add.php on line 30 Warning: implode() [function.implode]: Invalid arguments passed in /Applications/MAMP/htdocs/mynewscript/admin/cp/add.php on line 31 Thanks in advance! Hi , i am trying to make a to do list where i can add things i still need to do . i also want to remove items from the list when they are done , this is what i made now but it still misses a lot , my array keeps getting emptied when i add something.
im still a beginner in php. This is the file without the css included , i don't think it's relevant to this question to include it.
<?php Hello,
New to php&mysql here and need a little help.
I want to make category list with sub-categories and sub-sub-categories. The goal is when I load website I will see full list with master(root)categories . Then when I click some categories should load sub-category and if I click on sub-category should load sub-sub-category. Something like this:
Computers -> Motherboards -> Model 1 -> Model 2 -> etc. Monitors -> Model 1 -> Model 2As you can see max level of sub-category will be 2+root. Here is the perfect example what I want to do http://3docean.net/category I don't understand(know) also how exactly will look my database table? How to store categories and sub-categories. I don't want someone to write full code etc as I want to learn it but will be great if you guys can show me some good tutorial how to make it mostly database structure. Thank you in advance! p.s. Sorry for my English! Hello, I am doing (well trying to do, anyway) a script where I need to follow a link, and through its source (file_get_contents) i need to to follow each "category" and into its "subcategory" (and sometimes even SUBsubcategory). Lets say the first in the menu is called "Catfood", the second "Dogfood", you click on "Catfood" and you get a submenu with for example "Whiskas", another one called "Purina Pro", and you click "Whiskas" and you see a list of food called for example "Whiskas Junior Chicken" and "Whiskas Junior Fish". then after i have followed "Whiskas", i need to go back and follow "Purina Pro". then after "Purina Pro" i need to go back to "Dogfood" and do the same to its submenu + subsubmenu + food menu.. so yeah, thats pretty much it basically.. i have already used wget for windows to download the entire website to not put load on it all the time when trying stuff out.. i use RegEx to find categories, their products and price, and i got all that covered, it's just that the website isn't built very friendly for using Regex to tie lets say "Purina Pro" with being in the "Catfood" category, so i have to go through all categories and subcats to save the categories in maybe an array, and bind the subcategories to the main category ("Purina Pro" with "Catfood") i hope this all doesn't sound too errr weird lol, any help is very much appreciated even enough to just get me started on my own! =) ****************** EDIT BELOW: The menu looks a bit like this, though it's orinally not about cat or dogfood, they are just examples Catfood - Whiskas - Purina Pro Dogfood - Royal Canin - Puppy food - Grown - Senior - Bozita Robur I have two tables subcat and category structure subcat id_subcat|id_of_cat|subcat_name| and for main categories ID_cat|cat_name| now what I want to display them as Main category subcategory1 subcategory2 Main category2 subcategoryX etc... Here's the code I'm using but doesn't work,it doesn't display anything. <?php $query = " SELECT ID_cat, id_subcat, subcat_name, cat_name FROM subcat, category WHERE ID_cat=id_subcat"; $result = mysql_query($sql); $lastCat = null; while($row = mysql_fetch_assoc($result)) { # Check if you need to print the category_name if($lastCat != $row['ID_cat']) { # Not the same category as the last one! # Print it and save the ID $lastCat = $row['ID_cat']; echo "<br />". $row['ID_cat']; } # Print the sub category echo "<br />". $row['subcat_name']; } ?> I am working on a podcast list script. It displays the results of my mysql query correctly, but shows the results in 1 long list. Code: [Select] $query3 = "SELECT * FROM podcasts WHERE show_id = $show_id ORDER BY airdate DESC"; $result3 = mysql_query($query3) or die(mysql_error()); I would like to further filter the results instead of 1 hugely long list. For example, view by year, month etc... The 'airdate' is stored in the database as DATETIME. Is there a way to seperate the parts of the date: year, month, day using php ?? And if so how would I go about displaying only the podcasts for a specific year or month etc. ?? website located at http://www.eliteweboffers.com/lwr/podcasts.php Thanks. Hey guys I need some help, Im trying to generate a numbered list by using i++ and an if statement but I cant seem to get the values to start over to 0, here is a look at my code Code: [Select] $make = "SELECT * FROM category_description ORDER BY category_id ASC LIMIT 1000"; $makeresult = mysql_query($make); while($make1 = mysql_fetch_array($makeresult)){ $parent = "SELECT * FROM category WHERE parent_id = {$make1['category_id']} LIMIT 1000"; $parentresult = mysql_query($parent); while($parent1 = mysql_fetch_array($parentresult)){ if(($make1['category_id'] == $parent1['parent_id']) AND ($make1['name'] == $make1['name'])){ $i += 1; $count = $i; echo "[". $count . "]" . " " . $parent1['category_id'] . " " . $make1['category_id'] . " " . $parent1['parent_id'] . " " . $make1['name'] . "<br />"; Basically the output comes out like this: Code: [Select] [1] 100 10 10 Acura [2] 101 10 10 Acura [3] 102 10 10 Acura [4] 103 10 10 Acura [5] 104 10 10 Acura [6] 105 10 10 Acura [7] 106 10 10 Acura [8] 107 10 10 Acura [9] 108 10 10 Acura [10] 109 10 10 Acura [11] 110 10 10 Acura [12] 111 10 10 Acura [13] 112 10 10 Acura [14] 113 10 10 Acura [15] 114 10 10 Acura [16] 115 10 10 Acura [17] 116 10 10 Acura [18] 117 10 10 Acura [19] 118 10 10 Acura [20] 119 10 10 Acura [21] 120 10 10 Acura [22] 121 10 10 Acura [23] 122 10 10 Acura [24] 123 10 10 Acura [25] 124 10 10 Acura [26] 125 10 10 Acura [27] 126 11 11 Audi [28] 127 11 11 Audi [29] 128 11 11 Audi [30] 129 11 11 Audi [31] 130 11 11 Audi [32] 131 11 11 Audi [33] 132 11 11 Audi [34] 133 11 11 Audi [35] 134 11 11 Audi [36] 135 11 11 Audi [37] 136 11 11 Audi [38] 137 11 11 Audi But I need it to come out like this, so basically if Acura = Acura generate 1,2,3,4 etc and if Audi = Audi generate 1,2,3,4......Im still somewhat new to this would really appreciate the help if someone can point me in the right direction: Code: [Select] [1] 100 10 10 Acura [2] 101 10 10 Acura [3] 102 10 10 Acura [4] 103 10 10 Acura [5] 104 10 10 Acura [6] 105 10 10 Acura [7] 106 10 10 Acura [8] 107 10 10 Acura [9] 108 10 10 Acura [10] 109 10 10 Acura [11] 110 10 10 Acura [12] 111 10 10 Acura [13] 112 10 10 Acura [14] 113 10 10 Acura [15] 114 10 10 Acura [16] 115 10 10 Acura [17] 116 10 10 Acura [18] 117 10 10 Acura [19] 118 10 10 Acura [20] 119 10 10 Acura [21] 120 10 10 Acura [22] 121 10 10 Acura [23] 122 10 10 Acura [24] 123 10 10 Acura [25] 124 10 10 Acura [26] 125 10 10 Acura [1] 126 11 11 Audi [2] 127 11 11 Audi [3] 128 11 11 Audi [4] 129 11 11 Audi [5] 130 11 11 Audi [6] 131 11 11 Audi [7] 132 11 11 Audi [8] 133 11 11 Audi [9] 134 11 11 Audi [10] 135 11 11 Audi [11] 136 11 11 Audi [12] 137 11 11 Audi i need to create a to do list with php. but i dont want to use database .is there anything else i can use instead of using a database? i need to delete ,add functions .how may i do this? basicly it will have process.php,index.php and delete.php it may need more pages though. im a beginner so , code shouldnt be complicated and should be with explanation please . thanks. im trying to generate a birthday list for people who have birthdays today. Unfortunatly it keeps coming up 0 when there are birthdays today. here is the query: $birthday_query = $link->query("SELECT u.u_username, u.u_birthday FROM ".TBL_PREFIX."users u WHERE u.u_banned = '0' AND u_confirmed = '1' AND u_birthday LIKE '" . $link->asf_escape(sprintf('%2d-%2d-', $now['mday'], $now['mon'])) . "%' ORDER BY u_username ASC"); the query string is: Code: [Select] SELECT u.u_username, u.u_birthday FROM asf_users u WHERE u.u_banned = '0' AND u_confirmed = '1' AND u_birthday LIKE '25- 1-%' ORDER BY u_username ASC there is a birthday in the database which appears like: Code: [Select] 25-1-1986 but it still says no birthdays. any ideas? and yes the user is confirmed and not banned. I have a "select"-drop down bar and I want to have a numbered list in it, i've tried but it doesn't seem to be possible. Is there any way that i'm able to do this? hi guys, i made this code list US states in six columns....the problem is that it lists it across rather than down it lists it like thi Alabama Alaska Arizona blah1 blah2 blah3 blah4 blah5 blah6 when I want it to list like this Alabama blah2 Alaska blah3 Arizona blah 4 blah1 blah5 but not just two columns....I want 4 columns here is my code $query = mysql_query("SELECT * FROM states ORDER BY name ASC"); echo '<center><table width="250" border="0" cellpadding="5" cellspacing="0"> <tr>'; while($show = mysql_fetch_array($query)) { $column = 1+$column; if($column == 6) { $column = '1'; $break = '</td></tr>'; } else { $break = ''; } echo '<td> <table > <tr class="style5"> <td width="50%" align="left" height="23" nowrap>'.$show['name'].'</td> <td height="23" valign="middle" > </td> </tr> </table> '.$break.''; } echo '</table></center>'; Hi, I am trying to call the data from Mysql but I am getting an empty drop down list, this is the code: mysql: Code: [Select] create table years ( yearID integer auto_increment, year varchar(30), primary key (yearID) ); insert into years (yearID, year) values ('1', '2007-2008'); insert into years (yearID, year) values ('2', '2008-2009'); insert into years (yearID, year) values ('3', '2009-2010'); insert into years (yearID, year) values ('4', '2010-2011'); insert into years (yearID, year) values ('5', '2011-2012'); insert into years (yearID, year) values ('6', '2012-2013'); PHP: Code: [Select] <?php require_once('../Connections/connection.php'); ?> <?php $result = @mysql_query( "select yearID, year, from sss.years"); print "<p>Select a year:\n"; print "<select name=\"yearID\">\n"; while ($row = mysql_fetch_assoc($result)){ $yearID = $row[ 'yearID' ]; $year = $row[ 'year' ]; print "<option value=$yearID>$year\n"; } print "</select>\n"; print "</p>\n"; ?> Thank you! |