PHP - Numbered List
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 Similar TutorialsHello, I'm generating a list of questions from a database, say $questions. I'd like to number the questions AFTER I load them from the database (I know that I could enter a number associated with them in the database, but it could get tricky, as the questions will continually be updated and deleted). My question, then, is how can a create a new array which associates each question with a number. Thank you! I have an SQL query: SELECT username, dl_sumtotal FROM `vb_user` ORDER BY dl_sumtotal DESC LIMIT 0 , 30 Right now, its results display like this: username3: 500 username1: 400 username2: 300 How can I give these results a numbered column so it displays like this: 1: username3: 500 2: username1: 400 3: username2: 300 I would like to output that number in my PHP script. thanks for any help. Hi all, this is my first post on this site. I've built a few amateur sites in the past but am keen to utilize php combined with mysql for my current project. However, I have little knowledge of php and am just picking it up as I go (same way I've done for all my computer knowledge) What I'm looking for may sound simple, but I really don't know where to start and I'm hoping there are some kind souls here that will lend a hand. SQL Database Name Score John 42 Peter 46 Michael 56 Angela 46 (many rows like this) I am looking to output on my page a table of the top ten scores like this. However it's not quite that simple, should there be a tie on any score I want it to appear like so: 1. Michael 56 2. Angela 46 Peter 46 4. John 42 (onwards to 10) I want this to run from positions 1 thru 10, but should the 10th score in the database be equal to the 11th (12th, 13th etc) I would like them displayed too. For example: 9. Rafael 31 10. Sandy 29 Bernard 29 Jackie 29 Is this possible or would I be better off just sorting the info in excel and hard coding the info everytime? Hope somebody can help. Thanks in advance. 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! 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? =) 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 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! 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 there. I am building an online shop for my uni project and i want to make something like ebay's watchlist. However i'm not sure what whould be the best option to store watchlist information. I have two tables so far - users and products. If you have an idea how could i implement this, please sha ) Thanks for your help. What I want to be able to do is this: If I have a list of values in my database: 1 13 26 15 12 4 I do a query of this database and sort it asc so it looks like this: 1 4 12 13 15 26 I want to know how I can use php and/or sql query to find these values based off of "position" in the list. If I wanted the 3rd value in the list, that value would be 12. If i wanted the 2nd value in the list it would be 4. How would I go about doing this? Thank you in advance. 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. Hello All, i am trying to figerout how can i create a list of options that the user can input the values to as many lines as he wants and then getting the value of each row and inserting it to my DB (mysql) i havent found anyway to make this kind of list that is "open" for edit and is not limited... Can anyone suggest anything ? How can I edit this code to have images appear in it? <div id="rssSummaryList<?php echo intval($bID)?>" class="rssSummaryList"> <?php if( strlen($title)>0 ){ ?> <div class="rssSummaryListTitle"><?php echo $title?></div> <?php } ?> <?php $rssObj=$controller; $textHelper = Loader::helper("text"); if (!$dateFormat) { $dateFormat = t('jS F, Y'); } if( strlen($errorMsg)>0 ){ echo $errorMsg; }else{ foreach($posts as $itemNumber=>$item) { if( intval($itemNumber) >= intval($rssObj->itemsToDisplay) ) break; ?> <div class="rssItem"> <div class="rssItemTitle"> <a href="<?php echo $item->get_permalink(); ?>" <?php if($rssObj->launchInNewWindow) echo 'target="_blank"' ?> > <?php echo substr ($item->get_title(), 0, 100); ?> </a> </div> <div class="rssItemDate"><?php echo $item->get_date($dateFormat); ?></div> <div class="rssItemSummary"> <?php if( $rssObj->showSummary ){ echo $item->get_description(); } ?> <a href="<?php echo $item->get_permalink(); ?>" <?php if($rssObj->launchInNewWindow) echo 'target="_blank"' ?> >Read more</a> </div> </div> <?php } } ?> </div> Hello, I'm trying to walk a directory into a single array from a specific starting point. For example, lets say that I wanted to start at the specific directory "/content/users/n-bomb/" it would then begin to parse from that directory and list all sub-directories and directories and store them into an array. I'm not sure what would be the best array structure, but since I know the directory where I'm starting from (members base directory) I just want the array to be from their home directory. Ideally, I'd want a full-path to each directory as well, but I'm not sure how to incorporate that into the array structure. Example array of "/content/users/n-bomb/": [n-bomb] => Array ( [0] => /content/users/n-bomb/form.vb [1] => /content/users/n-bomb/song.mp3 [2] => /content/users/n-bomb/movie.avi [images] => Array ( [0] => /content/users/n-bomb/images/funny.png [1] => /content/users/n-bomb/images/mad.png [2] => /content/users/n-bomb/images/sad.png ) [documents] => Array ( [porn links] => Array ( [0] => /content/users/n-bomb/porn links/good websites.txt [1] => /content/users/n-bomb/porn links/bad websites.txt ) [0] => /content/users/n-bomb/documents/bills.txt [1] => /content/users/n-bomb/documents/website.txt [2] => /content/users/n-bomb/documents/emails.txt ) ) I started to mock up some code, but I can't quite get it right: private function walk($directory, $start = False) { if(!is_dir($directory)) return false; if(!$start) $this->information["structure"][basename($directory)] = array(); $scan = scandir($directory); natcasesort($scan); foreach($scan as $item) { if($item == "." || $item == "..") continue; $item = $directory . "/" . $item; if(is_dir($item)) $this->walk($item); if(is_file($item)) ($start) ? $this->information["structure"][] = $item : $this->information["structure"][basename($directory)][] = $item; } } With the above code I'm getting results like this: Array ( [documents] => Array ( [0] => /content/users/n-bomb/documents/bills.txt [1] => /content/users/n-bomb/documents/website.txt [2] => /content/users/n-bomb/documents/emails.txt ) [porn links] => Array ( [0] => /content/users/n-bomb/porn links/good websites.txt [1] => /content/users/n-bomb/porn links/bad websites.txt ) ) As you can see that "porn links" is not going inside of "documents". How can I resolve this issue so my code will output like the array structure that I want? Okay. Lets say i have a list box. Code: [Select] <select name="drop1" id="Select1" size="4" multiple="multiple"> <option value="1">item 1</option> <option value="2">item 2</option> <option value="3">item 3</option> <option value="4">item 4</option> <option value="0">All</option> </select> Now what i need it to do is open a file and replace the string [Replace] with whats in the list box. But it has to loop through everything in the list box understand? So How can i make it so that after it replaces 2 strings it gose to the next list item ect. after it replaces 2 more strings it goes to the next. So basically every 2 strings it will switch! Please help! here my code so far. <?php $fh = fopen(" myfile.txt", "r+"); if($fh==false) die("unable to create file"); ?> Please help! |