PHP - Moved: Created List In The While Loop Breaks Out Of The Div Wrapper
This topic has been moved to CSS Help.
http://www.phpfreaks.com/forums/index.php?topic=358236.0 Similar TutorialsI have an XML file (differences.xml) <element> <item code="lM" name="castle" type="building"> <cost>5000</cost> </item> ...more items.... </element> I have parser.php whih parses the XML and displays all item names in a checklist for the user to select items. These selected items are method=post back to parser.php which re-parses the XML where selected item = item name and SHOULD then display all selected items' names (and more): <?php if (isset($_GET['formSubmit'])) { $option = $_POST['option']; $option = array_values($option); if (!empty($option)){ $xml = simplexml_load_file('differences.xml'); $i = 0; $count = count($option); while($i < $count) { $selected = $xml->xpath("//item[@name='".$option[$i]."']"); echo $selected[$i]['name']; $i++; } }else{ echo "No items selected, Please select:"; } }else{ $xml = simplexml_load_file('differences.xml'); $object = $xml->xpath('//item'); $count = count($object); $i = 0; echo "<form method='POST' action='parser.php'>"; while($i < $count){ $xmlname = $object[$i]['name']; echo "<input type='checkbox' name='option[".$i."]' value='$xmlname'>".$xmlname; echo "<br>"; $i++; } echo "<br><input type='submit' name='formSubmit' value='Proceed'><br>"; echo "</form>"; } ?> The problem is, the parser is only displaying the first selected item and isn't outputting the rest. To clarify the code: - The first half executes only if items have been previously selected in the form. If no items were selected, it goes to the secod half, which parses the XML file and presents the checklist form for the user to select items. THIS WORKS GREAT. - After pressing the submit button, the items are sent using POST and the page is reloaded. THIS WORKS GREAT. - After reloading, the first half executes and finds the $_POST and resets the array so that it works with the coming loop. THIS WORKS GREAT. - The loop parses the XML and returns only those item names that have been selected in the $_POST. THIS DOES NOT WORK. So my question is: what's wrong with my code? The array $options has all the proper information, but the parser is only outputting the first item. All consecutive loops result in empty space with no output. I've been at this for 2 weeks and can't find the solution. Any help is appreciated! I have developed the following code, which queries a MySQL database and returns multiple results using several WHILE loops: Code: [Select] <?php # if submit_hash is present, then pull up the attendance from specified hash if($_GET['submit_hash']) { # select all the hashers from the specified hash $query = " SELECT h.*, ha.* FROM hashes as h, hashers as ha, hash_records as hr WHERE hr.hash_id = " . $_GET['hash_id'] . " && hr.hash_id = h.hash_id && hr.hasher_id = ha.hasher_id ORDER BY ha.hasher_name "; $result = mysql_query($query) or die('Error selecting Hash attendance.'); $x = 1; while($row = mysql_fetch_array($result)) { if($x == 1) { echo '<strong>' . $row['hash_num'] . ' ' . $row['hash_name'] . ' - ' . date("D, d M Y", strtotime($row['hash_date'])) . '</strong><em>Total Hashers: ' . mysql_num_rows($result) . '</em>'; $x++; } # see if this person was the hare if($row['hare_id'] == $row['hasher_id'] || $row['hare2_id'] == $row['hasher_id'] || $row['hare3_id'] == $row['hasher_id']) { $hare = '- hare'; } else { $hare = ''; } echo $row['hasher_name'] . ' <b>' . $hare . '</b>'; } } else if($_GET['submit_hasher']) { # if submit_hasher is present, pull up all of their hashes and aliases # select all the hashes that this person has attended $a_query = " SELECT h.*, ha.* FROM hashes as h, hashers as ha, hash_records as hr WHERE hr.hash_id = h.hash_id && hr.hasher_id = ha.hasher_id && hr.hasher_id = " . $_GET['hasher_id'] . " ORDER BY h.hash_date DESC "; $a_result = mysql_query($a_query) or die('Error selecting the person\'s Hashes . '); $x = 1; while($a_row = mysql_fetch_array($a_result)) { if($x == 1) { echo '<strong>Hash Attendance Record For ' . $a_row['hasher_name'] . '</strong> <em>(' . mysql_num_rows($a_result) . ' total hashes)</em>'; $x++; } echo '#' . $a_row['hash_num'].' ' . $a_row['hash_name'] . ' on ' . date("D, d M Y", strtotime($a_row['hash_date'])); # see if this person was a hare if($a_row['hasher_id'] == $a_row['hare_id'] || $a_row['hasher_id'] == $a_row['hare2_id'] || $a_row['hasher_id'] == $a_row['hare3_id']) { echo ' - <b>hare</b>'; } echo ''; } echo ''; } echo ' <table width="100%"> <br /> <tbody> <tr> <br /> <td> '; ?> The problem is that everything that is returned from the WHILE loops is displayed in a single line. However, I want the data displayed with a line break between each result, like this: Header Return 1 from WHILE loop Return 2 from WHILE loop Return 3 from WHLIE loop How do I need to modify the code to make it display appropriately? This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=332328.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=314698.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=347065.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347628.0 This topic has been moved to Editor Help (Dreamweaver, Zend, etc). http://www.phpfreaks.com/forums/index.php?topic=355418.0 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! how do i loop this so that the option in the drop down list loop. i tried this but get an error Code: [Select] <select name="age"><?php for ($i=10; $i<71; $i++;) { echo "<option value='$i'>$i</option>"; } ?></select> hello. 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> This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=323045.0 At the moment I have an sql query which retrieves an item and it's latest comments and it works well but I am now struggling to get it to output properly. My query is as follows:- Code: [Select] SELECT DISTINCT @rowtype:='1' AS rowType, //Type of row post or comment s.id AS rowId, //used as the 'grouper' to group posts and their comments s.id, s.body, //text of the post s.date, s.aboutItemId, //id of the attached item u1.id AS u1_id, u1.username AS u1_username, u1.name AS u1_name, u1.surname AS u1_surname FROM z_posts AS s LEFT JOIN z_users AS u1 ON s.id1 = u1.id UNION SELECT @rowtype:='2' AS rowType, l.id2 AS rowId, l.id, l.body, l.date, l.id1 AS u1_id, NULL AS u1_username, NULL AS u1_name, NULL AS u1_surname FROM ( SELECT id2, COALESCE( ( SELECT id FROM z_postComments li WHERE li.id2 = dlo.id2 ORDER BY li.id2, li.id LIMIT 14, 1 ), CAST(0xFFFFFFFF AS DECIMAL)) AS mid FROM ( SELECT DISTINCT id2 FROM z_postComments dl ) dlo ) lo, z_postComments l WHERE l.id2 >= lo.id2 AND l.id2 <= lo.id2 AND l.id <= lo.mid ORDER BY rowId DESC, rowType ASC, date DESC What I want is to output the posts as lis in a ul with the comments for each item in their own ul within each post li so it looks like this:- <ul> <li>Post2 <ul> <li>Comment 2 on post 2</li> <li>Comment 1 on post 2</li> </ul> </li> <li>Post1 <ul> <li>Comment 3 on post 1</li> <li>Comment 2 on post 1</li> <li>Comment 1 on post 1</li> </ul> </li> </ul> How can I create this this via php? Hi All, I've a loop which lists a series of options as checkboxes. What I'd like to do is set 1 as a default. But I've no idea how to do it!? Here's the code: <?php $i = 0; ?> <?php if ( bp_has_groups() ) : while ( bp_groups() ) : bp_the_group(); ?> <input type="checkbox" id="field_reg_groups_<?php echo $i; ?>" name="field_reg_groups[]" value="<?php bp_group_id(); ?>" /><?php bp_group_name(); ?> <?php } ?> <?php $i++; ?> Any help is much appreciated TIA This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=329438.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=315341.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=346652.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=354677.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=306079.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=316599.0 |