PHP - Xml Ignoring Comments
Hi all,
I have another uestion. I am currently working with an XML document that has some comments in it that need to stay however it is messing up my parser that I am working on. How can I get around this issue and make the php parser ignore the comments? here is a snippet of the code I am working on. php Code: [Select] //open XML file containing data for current slide $currentslidefilepath = "slides/xml/"; $currentslidefilepath .= $slides[$currentslide]; $currentSlideXml = simplexml_load_file($currentslidefilepath); XML Quote <!-- there are some comments here --> <Basic> <another>some data</another> </Basic> Similar TutorialsI have a problem with the "comments count" in the toggle link in my blog: www.albertosotophotography.com
I have this script for show/hide comments in main page:
<script type= "text/javascript"> // Show/Hide Comments jQuery(document).ready(function() { // Get #comments div var uniqueAppend = 1; var tempName = 'comments'; while(jQuery("#comments").length > 0 ){ jQuery("#comments").attr('id',tempName + uniqueAppend++).addClass('commentContainer') } var commentsDiv = jQuery('.commentContainer'); // Only do this work if that div isn't empty if (commentsDiv.length) { // Hide #comments div by default jQuery(commentsDiv).hide(); // Append a link to show/hide jQuery('<a/>') .attr('class', 'toggle-comments') .attr('href', '#') .html('Notes') .insertAfter(commentsDiv); // Encase button in .toggle-comments-container div jQuery('.toggle-comments').wrap(jQuery('<div/>', { class: 'toggle-comments-container' })) // When show/hide is clicked jQuery('.toggle-comments').on('click', function(e) { e.preventDefault(); // Show/hide the div using jQuery's toggle() var commentContainer = jQuery(this).parent('.toggle-comments-container').prev('.commentContainer'); jQuery(commentContainer).slideToggle('slow', function() { // change the text of the anchor var anchor = jQuery(commentContainer).siblings('.toggle-comments-container').children('.toggle-comments'); var anchorText = anchor.text() == 'Notes' ? 'Hide' : 'Notes'; jQuery(anchor).html(anchorText); }); }); } // End of commentsDiv.length }); // End of Show/Hide Comments </script>I use: .html('<?php comments_number( '0 notes', '1 note', '% notes' ); ?>')for name the "comments toggle link" with the count of comments for each single post. The problem is that all posts shows the same count: the comments presents in the first post. Someone can help me? Alberto Hi, I have a database table which is full of books e.g book_title, book_author, book_date etc. Im trying to work out a way to list all the authors without duplicating them, if that makes sense. If I do a simple query and then display the book_author in a loop it will show multiple entries for each author. I just want it to display each author once. Hope that makes sense lol sorry Im a newbie. Anyone know how I can do it ? Thanks in advance, Scott. I have any array $DF containing numeric variables, I want the minimum value of the array stored in $val but ignoring any zeros i.e. the lowest number that is not 0. Is this possible? I have a php script. I defined a variable outside of a function, but i cannot echo the variable inside the function. When I execute this: <?PHP $testvar = "test worked!"; testfunction(); function testfunction(){ echo $testvar; } ?> Nothing happens. what am i doing wrong. I did this on my local host. Apache running on Windows Vista Ultimate 32 bit Edition. Thanks in advance. Greetings! I have a CSV file that looks something like this: Quote ,,,,,,,,sdfsdf sdfsdf,,,,,,,,,,,,,,,,,,,,,,sdfsdfsdf:,,,,,,,,2011-04-27,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,dfgdfg,,fgh,,,,,gfh,,,,,,,,,,,,,,fghfgh,,,,,fghf,, fghfh,, fgh,,,,,,fhfgh,,,, Code: [Select] <?php $handle = fopen("csv.csv", "r"); while (($data = fgetcsv($handle, 5000, ",")) !== FALSE) { echo "<pre>"; print_r($data); echo "<pre>"; } ?> Now this prints everything, could someone please provide me with an example of how I can ignore the "empty fields"? Thanks in advance! I have a dynamic menu (jglidemenu) installed on my site. It works fine on my HTML pages but on my PHP pages the font formatting from the menu's style sheet isn't working and I haven't been able to figure out why. Here's a page where the menu is working correctly: http://www.greenbayeasthighschool.com and here's a page where the formatting fails: http://www.greenbayeasthighschool.com/staff_by_lastname.php This is my first attempt at creating a page with PHP. Is it not possible to use CSS formatting on a page that includes PHP content? Thanks in advance for any help. Basically I have the following code (posted below) foreach($char_xml->characterInfo->characterTab->items->item as $item) { //get the item id $item_id = $item->attributes()->id; //get the xml doc for that item from wow armory $url = "http://www.wowarmory.com/item-info.xml?i=" . $item_id; $data = fetchXML($url); //create a SimpleXML object to parse the xml $item_xml = new SimpleXmlElement($data); //print the item's name echo "<li type=square>" . $item_xml->itemInfo->item->attributes()->name . " "; echo "<b>(" . $item_xml->itemInfo->item->attributes()->level . ")</b></br>"; //calculate gear score total $calc=$calc+$item_xml->itemInfo->item->attributes()->level; } echo '</ul>'; //print the total item level echo '<b>Total Additive Item Score (Equipped):</b>' . $calc; echo '<br>'; //calculate the average item level(equipped) $ilvl=$calc/16; echo '<b>Average Item Score (Equipped):</b>' . round($ilvl) . "<br><br>"; It is working relatively well for what I am trying to accomplish. It pulls xml data from wowarmory and uses it to calculate a player's "average item level". The problem I am running in to is if a player is equipped with certain items (that should not be calculated), the average is incorrect. I know atleast the shirt, tabard and off-hand need to be ignored IF equipped. I am trying to find something relative to all 3 items in the xml data and thus tell the script to disregard them. Here is a printed example of the array I am working with (warning its LONG). This is an example of a player that has these 3 extra items. Shirt (Block 4), off-hand(shield) (Block 17), and Tabard (Block19) : Quote SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=59458 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_gizmo_newgoggles [id] => 59458 [level] => 359 [name] => Energized Bio-Optic Killshades [quality] => 4 [requiredSkill] => Engineering [requiredSkillRank] => 525 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 150956 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) [createdBy] => SimpleXMLElement Object ( [spell] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => trade_engineering [id] => 81720 [name] => Energized Bio-Optic Killshades ) [reagent] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 20 [icon] => inv_misc_pyriumbar [id] => 52186 [name] => Elementium Bar [quality] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 20 [icon] => inv_stone_15 [id] => 54849 [name] => Obsidium Bar [quality] => 1 ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 2 [icon] => inv_misc_truegold [id] => 58480 [name] => Truegold [quality] => 2 ) ) ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=67130 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_misc_forestnecklace [id] => 67130 [level] => 359 [name] => Dorian's Lost Necklace [quality] => 4 [type] => Miscellaneous ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 53434 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=58129 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_shoulder_mail_dungeonmail_c_04 [id] => 58129 [level] => 346 [name] => Seafoam Mantle [quality] => 3 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 112607 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_largeshard_superior [id] => 52721 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Heavenly Shard [quality] => 3 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=14617 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_shirt_red_01 [id] => 14617 [level] => 1 [name] => Sawbones Shirt [quality] => 1 [type] => Miscellaneous ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 6250 ) ) [dropCreatures] => SimpleXMLElement Object ( [creature] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Scholomance [areaUrl] => fl[source]=dungeon&fl[dungeon]=scholomance&fl[boss]=all&fl[difficulty]=all [classification] => 1 [dropRate] => 2 [heroic] => 1 [id] => 11261 [maxLevel] => 42 [minLevel] => 42 [name] => Doctor Theolen Krastinov [title] => The Butcher [type] => Humanoid [url] => fl[source]=dungeon&fl[dungeon]=scholomance&fl[difficulty]=heroic&fl[boss]=11261 ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=56563 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_chest_raidshaman_i_01 [id] => 56563 [level] => 359 [name] => Twilight Scale Chestguard [quality] => 4 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 101750 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) [createdBy] => SimpleXMLElement Object ( [spell] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => trade_leatherworking [id] => 78489 [name] => Twilight Scale Chestguard ) [reagent] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 10 [icon] => item_savageleather [id] => 52976 [name] => Savage Leather [quality] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_rubysanctum2 [id] => 52979 [name] => Blackened Dragonscale [quality] => 1 ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_pelt_12 [id] => 52980 [name] => Pristine Hide [quality] => 3 ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_volatilewater [id] => 52326 [name] => Volatile Water [quality] => 1 ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_volatilefire [id] => 52325 [name] => Volatile Fire [quality] => 1 ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_volatilelife_green [id] => 52329 [name] => Volatile Life [quality] => 1 ) ) ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=56538 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_belt_mail_raidshaman_i_01 [id] => 56538 [level] => 359 [name] => Stormleather Sash [quality] => 4 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 53729 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) [createdBy] => SimpleXMLElement Object ( [spell] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => trade_leatherworking [id] => 78462 [name] => Stormleather Sash ) [reagent] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 10 [icon] => item_savageleather [id] => 52976 [name] => Savage Leather [quality] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_rubysanctum2 [id] => 52979 [name] => Blackened Dragonscale [quality] => 1 ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_pelt_12 [id] => 52980 [name] => Pristine Hide [quality] => 3 ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_volatilewater [id] => 52326 [name] => Volatile Water [quality] => 1 ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_volatilefire [id] => 52325 [name] => Volatile Fire [quality] => 1 ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_volatilelife_green [id] => 52329 [name] => Volatile Life [quality] => 1 ) ) ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=67148 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_pant_raidshaman_i_01 [id] => 67148 [level] => 359 [name] => Kilt of Trollish Dreams [quality] => 4 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 196103 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=62363 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_boots_raidshaman_i_01 [id] => 62363 [level] => 359 [name] => Earthmender's Boots [quality] => 4 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 159778 ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=59310 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_bracer_raidshaman_i_01 [id] => 59310 [level] => 359 [name] => Chaos Beast Bracers [quality] => 4 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 102564 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) [dropCreatures] => SimpleXMLElement Object ( [creature] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Blackwing Descent [classification] => 3 [dropRate] => 3 [id] => 43296 [maxLevel] => 88 [minLevel] => 88 [name] => Chimaeron [type] => Beast ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Blackwing Descent [classification] => 3 [dropRate] => 2 [id] => 47774 [maxLevel] => 88 [minLevel] => 88 [name] => Chimaeron [type] => Beast ) ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=60314 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_glove_raidshaman_i_01 [id] => 60314 [level] => 359 [name] => Gloves of the Raging Elements [quality] => 4 [type] => Mail ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 105223 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) [dropCreatures] => SimpleXMLElement Object ( [creature] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Baradin Hold [classification] => 1 [dropRate] => 1 [id] => 47120 [maxLevel] => 88 [minLevel] => 88 [name] => Argaloth [type] => Demon ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Baradin Hold [classification] => 1 [dropRate] => 1 [heroic] => 1 [id] => 51350 [maxLevel] => 88 [minLevel] => 88 [name] => Argaloth [type] => Demon ) ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=59220 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_misc_rubystar [id] => 59220 [level] => 359 [name] => Security Measure Alpha [quality] => 4 [type] => Miscellaneous ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 53434 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) [dropCreatures] => SimpleXMLElement Object ( [creature] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Blackwing Descent [classification] => 1 [dropRate] => 3 [id] => 42180 [maxLevel] => 88 [minLevel] => 88 [name] => Toxitron [type] => Mechanical ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Blackwing Descent [classification] => 1 [dropRate] => 3 [id] => 49050 [maxLevel] => 88 [minLevel] => 88 [name] => Toxitron [type] => Mechanical ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Blackwing Descent [classification] => 1 [dropRate] => 2 [id] => 49056 [maxLevel] => 88 [minLevel] => 88 [name] => Arcanotron [type] => Mechanical ) ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=67129 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_misc_pearlring1 [id] => 67129 [level] => 359 [name] => Signet of High Arcanist Savor [quality] => 4 [type] => Miscellaneous ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 53434 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=62465 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_misc_branch_01 [id] => 62465 [level] => 359 [name] => Stump of Time [quality] => 4 [type] => Miscellaneous ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 80507 ) ) [translationFor] => SimpleXMLElement Object ( [@attributes] => Array ( [factionEquiv] => 0 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_misc_branch_01 [id] => 62470 [level] => 359 [name] => Stump of Time [quality] => 4 ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=62047 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_inscription_tarot_volcanocard [id] => 62047 [level] => 359 [name] => Darkmoon Card: Volcano [quality] => 4 [type] => Miscellaneous ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 107343 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=67131 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_misc_cape_cataclysm_caster_c_01 [id] => 67131 [level] => 359 [name] => Ritssyn's Ruminous Drape [quality] => 4 [type] => Cloth ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 99205 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=61338 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_mace_1h_pvp400_c_01 [id] => 61338 [level] => 359 [name] => Vicious Gladiator's Gavel [quality] => 4 [type] => One-Handed Maces ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 334291 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=55070 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [icon] => inv_shield_bwdraid_d_02 [id] => 55070 [level] => 359 [name] => Elementium Stormshield [quality] => 4 [type] => Shields ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 115029 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) [createdBy] => SimpleXMLElement Object ( [spell] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => spell_shadow_sealofkings [id] => 76455 [name] => Elementium Stormshield ) [reagent] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 8 [icon] => inv_misc_ebonsteelbar [id] => 53039 [name] => Hardened Elementium Bar [quality] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 1 [icon] => inv_misc_pyriumbar [id] => 52186 [name] => Elementium Bar [quality] => 1 ) ) ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=64672 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_shield_56 [id] => 64672 [level] => 359 [name] => Relic of Norgannon [quality] => 4 [type] => Relic ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [sellPrice] => 101843 ) ) [disenchantLoot] => SimpleXMLElement Object ( [@attributes] => Array ( [requiredSkillRank] => 500 ) [item] => SimpleXMLElement Object ( [@attributes] => Array ( [canAuction] => 1 [dropRate] => 6 [icon] => inv_misc_crystalepic [id] => 52722 [level] => 85 [maxCount] => 1 [minCount] => 1 [name] => Maelstrom Crystal [quality] => 4 [type] => Enchanting ) ) ) ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [globalSearch] => 1 [lang] => en_us [requestQuery] => i=65904 [requestUrl] => /item-info.xml ) [itemInfo] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [@attributes] => Array ( [icon] => inv_misc_tabard_tolvir [id] => 65904 [level] => 85 [name] => Tabard of Ramkahen [quality] => 1 [type] => Miscellaneous ) [cost] => SimpleXMLElement Object ( [@attributes] => Array ( [buyPrice] => 10000 [sellPrice] => 2500 ) ) [vendors] => SimpleXMLElement Object ( [creature] => SimpleXMLElement Object ( [@attributes] => Array ( [area] => Uldum [classification] => 0 [heroic] => 1 [id] => 48617 [maxLevel] => 83 [minLevel] => 83 [name] => Blacksmith Abasi [title] => Ramkahen Quartermaster [type] => Humanoid ) ) ) ) ) ) I guess the shirt and tabard can be identified by the "[Quality]=>1" which no other items should typically have. The big issue comes with the third odd ball (off hand). This off-hand could be a shield or any weapon with few exceptions depending on the player class. As I continue to try and figure this out, one solution could be to first take the previous two "[Quality]=>1" items out of the equation IF they exist, then ONLY IF there are 17 items remaining subtract the value of block/iteration 17 before calulating as usual. If 16 items, then just run $calc is it currently is. How would I accomplish this? I do not mind displaying the item's name, in fact I would prefer to keep the item list as it currently I just need to not include the said items in the item level average. I know this is probably relatively straight forward to accomplish and that I am a noob, but would be grateful of your assistance. Thanks. I’m trying to work out how I can use php gd to take an image, in this case it’s a rectangle that has text in the middle and the rest is transparent, so it’s a png with just text in the centre.
I have another image which is a texture. Its also a rectangle of the same size. I have managed to merge the two together so the texture on top of the text image but it covers the entire image rather than just the text in the middle.
what I need it to do it apply the texture to the text in the image and ignore the surrounding transparent pixels.
Hello! I'm trying to dive into Dreamweaver's code so that I can better understand what the heck it's doing in order to modify it to my specific needs. My PHP book is great, but it just seems like Dreamweaver's code is much more complicated than how I'd write it based on what I've read about PHP (Disclaimer: been with PHP for a week). It would be incredibly helpful if someone could write comments for each of the lines in terms of what it's doing (the more specific the better). I appreciate that this is a bit of a tedious question to ask, but it would be really appreciated. Thank you. Code: [Select] $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) { $insertSQL = sprintf("INSERT INTO users (first_name, last_name, user_type, email, school_id) VALUES (%s, %s, %s, %s, %s)", GetSQLValueString($_POST['first_name'], "text"), GetSQLValueString($_POST['last_name'], "text"), GetSQLValueString($_POST['user_type'], "text"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($_POST['school_id'], "int")); mysql_select_db($database_connalgebra, $connalgebra); $Result1 = mysql_query($insertSQL, $connalgebra) or die(mysql_error()); // The code below gives the last autogenerated userid. $id = mysql_insert_id(); $updateusername = "UPDATE users SET username = CONCAT(first_name, $id) WHERE user_id = $id"; $Result2 = mysql_query($updateusername, $connalgebra) or die(mysql_error()); // $insertGoTo = "add_user.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_connalgebra, $connalgebra); $query_rsSchools = "SELECT school_id, school_state, school_city, school_name, school_country FROM schools ORDER BY school_name ASC"; $rsSchools = mysql_query($query_rsSchools, $connalgebra) or die(mysql_error()); $row_rsSchools = mysql_fetch_assoc($rsSchools); $totalRows_rsSchools = mysql_num_rows($rsSchools); Hello im trying to make a comment feature by having a link under my pictures kommentar.php?link=1 Then use the link=1 to see what comments that should be taken from the database. The comments have a linkid like this Linkid: Text: 1 a comment on first picture 1 another comment on first picture 2 a comment on second picture 2 another comment on second picture But i can't get my php to echo all the comments with the linkid of for example 1 without having to get them all separately. This is my script: <?php ob_start(); $host="localhost"; $username="****"; $password="******"; $db_name="db"; $tbl_name="comment"; mysql_connect($host, $username, $password)or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $linkid=filter_input(INPUT_GET,'link'); $sql="SELECT * FROM $tbl_name WHERE linkid='$linkid'"; $result=mysql_query($sql); $grejs=null; while(mysql_fetch_row($result)){ $grejs.="$row[0]"; } echo $grejs; ob_end_flush(); ?> Is it true that PHP Comments are hidden from end users? And is it dangerous to put extensive comments in your code (e.g. links to developer sites, article excerpts, etc)? I am re-factoring my website, and have found some really helpful articles that I'd like to post in my code so I don't forget what I'm doing 6 months from now, but don't want to cause any issues. (I know this sounds wimpy, but I am a newbie?!) Debbie I have one small question about comments. say you have a code like this Code: [Select] <?php $lol = 1; $rofl = 2; $lmao = 3; // Above are my variable's echo 'this does not get executed because the apostrophy in the comment acts as the start'; ?> Now if I wrote this code the apostrophe in variable acts as a quote and does not end until it meets another to end it. Why does this do that? I thought that when you start a comment that whole line gets ignored. Could this possible be happening because of my text editor( I use textpad )? If so could you recommend a good text editor, thanks. Hello, I have built a blog in php but. On each article in the blog people are able to comment. I would now like to build a system where people can vote on the comment up/down with Ajax. In my comments database I have a table that looks like this: id / article_id / user_id / dateposted / comment / voteup / votedown I would like it to look like this: Any ideas how I can do this? Tutorials online? Thanks a million Got this script he http://www.codewalkers.com/c/a/Database-Articles/PHPMySQL-News-with-Comments/6/ Everything works, and I mean EVERYTHING. The problem is, when the form gets submitted, the database isn't being queried/updated/whatever. It worked at first, but after I started customizing/modifying it, it quit working. Here's my modified script: Code: [Select] <?php //**********************************// //**********************************// /*******user config variables********/ /* max number of news items to show */ //**********************************// //**********************************// $max_items = 5; //***********************// //***********************// //***********************// //make database connection// //***********************// //***********************// //***********************// $db = mysql_connect ('my hostname','my username','my password'); mysql_select_db ('my database name',$db); //If not all of the news articles are being displayed... function displayNews($all = 0) { /* bring in two variables * $db is our database connection * $max_items is the maximum number * of news items we want to display */ global $db, $max_items; /* query for news items */ if ($all == 0) { /* this query is for up to $max_items; only five news articles will be displayed */ $query = "SELECT id,title,body," . "DATE_FORMAT(date, '%m-%d-%Y') as date " . "FROM news ORDER BY id DESC LIMIT $max_items"; } else { /* this query will get all news; $max_items will be false */ $query = "SELECT id,title,body," . "DATE_FORMAT(date, '%Y-%m-%d') as date " . "FROM news ORDER BY id DESC"; } $result = mysql_query ($query); while ($row = mysql_fetch_assoc ($result)) { /* place table row data in * easier to use variables. * Here we also make sure no * HTML tags, other than the * ones we want are displayed */ $date = $row['date']; $title = htmlentities ($row['title']); $news = nl2br (strip_tags ($row['body'], '<a><b><i><u>')); $url = $row['id']; /* display the data (news) */ echo "<table border=\"0\" width=\"100%\"><tr><td><strong><h2><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id={$row['id']}\">$title</a></h2></strong> <em>posted on $date</em> | by <strong>DJ Smiley</strong></td></tr>\n"; echo "<tr><td>"; echo stripslashes(substr($news, 0, 500)); echo "...<a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id={$row['id']}\">read more</a></td></tr>\n"; /* get number of comments from database */ $comment_query = "SELECT count(*) FROM comments " . "WHERE news_id={$row['id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); /* display number of comments with link; add twitter, facebook, digg, and share widgets; and add email sharing widget */ echo "</table>\n<table width=\"100%\" border=\"0\"> <tr> <td width=\"6%\"><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id={$row['id']}\"><img src=\"images/Icons/Comment/2.png\" width=\"20\" height=\"20\" class=\"fltlft2\"/></a>$comment_row[0]</td> <td width=\"13%\"><!-- FreeTellaFriend BEGIN --> <a href=\"http://www.freetellafriend.com/tell/\" onclick=\"window.open('http://www.freetellafriend.com/tell/?option=email&heading=Tell+A+Friend&bg=14&url=http%3A%2F%2Fhttp://www.djsmiley.net/index.php?action=show&id={$row['id']}', 'freetellafriend', 'scrollbars=1,menubar=0,width=435,height=500,resizable=1,toolbar=0,location=0,status=0,left='+(screen.width-435)/2+',top='+(screen.height-500)/3);return false;\"><img alt=\"Tell a Friend\" src=\"http://serv1.freetellafriend.com/s14.png\" border=\"0\" /></a> <!-- FreeTellaFriend END --></td> <td width=\"81%\"><span class=\"st_twitter_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Tweet\" st_title=\"{$row['title']}\"></span><span class=\"st_facebook_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Share\" st_title=\"{$row['title']}\"></span><span class=\"st_email_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Email\"></span><span class=\"st_sharethis_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Share\"></span></td> </tr> </table><br>"; } /* if we aren't displaying all news, * then give a link to do so */ if ($all == 0) { echo "<br><div style=\"border-radius: 10px; border: solid 2px #E5E5E5; padding: 10px; margin: 5px; background: #F6F6F6;\"></p><a href=\"{$_SERVER['PHP_SELF']}" . "?action=all\">View All Articles</a></p></div>"; } } //function for displaying only one item function displayOneItem($id) { global $db; /* query for item */ $query = "SELECT * FROM news WHERE id=$id"; $result = mysql_query ($query); $row = mysql_fetch_assoc($result); /* easier to read variables and * striping out tags */ $title = htmlentities ($row['title']); $news = nl2br (strip_tags ($row['body'], '<a><b><i><u>')); /* if we get no results back, error out */ if (mysql_num_rows ($result) == 0) { echo "This news article does not exist!\n"; return; } echo "<TABLE border=\"0\" width=\"100%\">\n"; /* displays individual article user visits */ echo "<tr><td><strong><h2><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id={$row['id']}\">$title</a></h2></strong> <em>posted on $date</em> | by <strong>DJ Smiley</strong></td></tr>\n"; echo "<tr><td>"; echo stripslashes($news); echo "</td></tr>\n"; echo "</table>\n"; echo "<br>\n"; echo ("</table>\n<table width=\"100%\" border=\"0\"> <tr> <td width=\"6%\"><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id={$row['id']}\"><img src=\"images/Icons/Comment/2.png\" width=\"20\" height=\"20\" class=\"fltlft2\"/></a>$comment_row[0]</td> <td width=\"13%\"><!-- FreeTellaFriend BEGIN --> <a href=\"http://www.freetellafriend.com/tell/\" onclick=\"window.open('http://www.freetellafriend.com/tell/?option=email&heading=Tell+A+Friend&bg=14&url=http%3A%2F%2Fhttp://www.djsmiley.net/index.php?action=show&id={$row['id']}', 'freetellafriend', 'scrollbars=1,menubar=0,width=435,height=500,resizable=1,toolbar=0,location=0,status=0,left='+(screen.width-435)/2+',top='+(screen.height-500)/3);return false;\"><img alt=\"Tell a Friend\" src=\"http://serv1.freetellafriend.com/s14.png\" border=\"0\" /></a> <!-- FreeTellaFriend END --></td> <td width=\"81%\"><span class=\"st_twitter_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Tweet\"></span><span class=\"st_facebook_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Share\"></span><span class=\"st_email_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Email\"></span><span class=\"st_sharethis_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Share\"></span></td> </tr> </table>"); /* now show the comments */ displayComments($id); } function displayComments($id) { /* bring db connection variable into scope */ global $db; /* query for comments */ $query = "SELECT * FROM comments WHERE news_id=$id"; $result = mysql_query ($query); echo "<h2>Comments</h2>"; /* display the all the comments */ while ($row = mysql_fetch_assoc ($result)) { //sets variables $comment = strip_tags ($row['comment'], '<a><b&><i><u>'); $comment = nl2br ($comment); $name = htmlentities ($row['name']); $time = ($row['time']); echo "<div style=\"border-radius: 10px; border: solid 2px #E5E5E5; padding: 10px; margin: 5px; background: #F6F6F6;\"><p><table border=\"0\" width=\"100%\"><tr><td><strong>$name</strong> says:</td></tr></table> <table><tr><td><img src=\"images/Icons/People/Anonymous 2.png\" alt=\"\" width=\"50\" height=\"50\"/></td><td>$comment</td></tr></table><table><tr><td>added on $time</td></tr></table></p></div>"; } /* add a form where users can enter new comments */ echo "<form action=\"{$_SERVER['PHP_SELF']}" . "?action=addcomment&id=$id\" method=post> <h2>Comment</h2><table width=\"37%\" border=\"0\"> <tr> <td width=\12%\">Name:</td> <td width=\"88%\"><label> <input type=\"text\" name=\"name\" id=\"name\" class=\"commentBoxforms\"> </label></td> </tr> <tr> <td>Comment:</td> <td><label> <textarea name=\"comment\" id=\"comment\" cols=\"45\" rows=\"5\" class=\"commentField1\"></textarea> </label></td> </tr> <tr> <td> </td> <td><label> <input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Comment\" class=\"Button1\"> </label></td> </tr> </table> </form>\n"; } function addComment($id) { global $db; /* insert the comment */ $query = "INSERT INTO comments " . "VALUES('',$id,'{$_POST['name']}'," . "'{$_POST['comment']}')"; mysql_query($query); echo "Your comment has been posted!<br>\n"; echo "<a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id=$id\">Return To Previous Page</a>\n"; } /* this is where the script decides what do do */ switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'all': displayNews(1); break; case 'addcomment': addComment($_GET['id']); break; default: displayNews(); } ?> Can anyone tell me where this script is going wrong? I've literally tried EVERYTHING. I even went back to the original script and compared every single character to mine, but NO luck. PLEASE HELP! Hi, i wonna put on my website to ghosts can post comments and registred users, and i made 2 tables ghosts and users, now i need method to save ghosts on that table, but how to save them with uniq number? I tried session_id, but it works bad, when someone comment it write in db his session_id, but after some time, when someone else comment, it can get his session_id, or no ? Hi all, I've got a news table as such; `id` int(255) NOT NULL auto_increment, `title` mediumtext NOT NULL, `postedby` mediumtext NOT NULL, `text` mediumtext NOT NULL, `brief` mediumtext NOT NULL, `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, `image` varchar(255) NOT NULL default '', PRIMARY KEY (`id`) I was wondering in PHP how would i be able to add comments to the news? i.e Form: Name, IP (hidden), comments I'll add the name, ip and comments to the database But how do i go around adding that into php? Hey guys not sure if this is the right spot for this 100% but I hope it is. I have a website that I'm making for a class project and I would like it to be a Movie Review type site. What I want to happen is that a person searches for the movie, and once if they find the movie it goes to another page saying if it was found or not. And if it was found information of the movie would come up. I made a comment section for people to be able to post what they thought about the movie. (It doesn't work yet but it should be up soon) But anyway how would I make it so like say a person searches for "avatar" and the movie pops up with the information, that the review is for avatar and only avatar. Then next they search for Lord of the rings, and only lord of the rings reviews pop up? And just to let ya know I'm not a super coder with this stuff and I am using dreamweaver cs5 to do a lot of the coding. Any and all help would be appreciated. ok here is my script , for some reason , it adds the comment and all it works great , but it wont add it to the notifications table in my database Code: [Select] <?php include("../includes.php"); $session = $logOptions_id; if($session) { $to_id = $_POST['user_id']; $post_id = $_POST['post_id']; $comment = mysql_real_escape_string($_POST['comment']); $date = mktime(); mysql_query("INSERT INTO comments SET user_id='$to_id', from_id='$session', post_id='$post_id', comment='$comment', date='$date'"); $id = mysql_insert_id(); $query = mysql_query("SELECT * FROM comments WHERE post_id='$post_id' AND from_id!='$session' AND state='0' GROUP BY from_id"); if(mysql_num_rows($query)>0) { $row1 = mysql_fetch_assoc(mysql_query("SELECT * FROM posts WHERE id='$post_id'")); $post_from2 = $row1['from_id']; mysql_query("INSERT INTO notifications SET user_id='$post_from2', from_id='$session', post_id='$id', action_type='4', date='$date'"); while($row = mysql_fetch_array($query)) { $post_from = $row['from_id']; if($post_from!=$post_from2) { mysql_query("INSERT INTO notifications SET user_id='$post_from', from_id='$session', post_id='$id', action_type='4', date='$date'"); } } } else { $row1 = mysql_fetch_assoc(mysql_query("SELECT * FROM posts WHERE id='$post_id'")); $post_from = $row1['from_id']; mysql_query("INSERT INTO notifications SET user_id='$post_from', from_id='$session', post_id='$id', action_type='4', date='$date'"); } $query = mysql_query("SELECT * FROM comments WHERE id='$id' AND state='0'"); comments($query); } ?> What does this code do/mean? /* * @the vars array * @access private */ TomTees Hi I'm wondering how I can output nested comments. I have written a viewthread.php file that works nicely so far. From index.php it gets the IDOfThread and passes this to a $number then outputs all the comments assigned to the Thread ID However I'd like to be able to respond to each comment to create nested comments This is my viewthread.php so far <!DOCTYPE html> <html> <header> <link href="styles.css" rel="stylesheet" type="text/css" media="all"> <title>test Image Board</title> <div class="header"> <a href="index.php" class="logo">test forum online</a> <div class="header-right"> <a class="active" href="#home">Home</a> <a href="#news">News</a> <a href="#contact">Education</a> <a href="#about">Tech</a> </div> </div> </header> <body> <!-- <a href="CreateThread.php"> <h1>Create Thread</h1> </a> --> <div class ='Thread-grid-container'> <?php include 'dbconnect.php'; $number = intval($_GET['id']) ; session_start(); $_SESSION['id'] = $number ; $query = mysqli_query($conn, "SELECT * FROM Threads where id=$number") or die (mysqli_error($conn)); //Output Grid layout for a Thread post while ($row = mysqli_fetch_array($query)) { //output picture from upload folder $imageURL = 'upload/'.rawurlencode($row["filename"]); echo " <div class ='Thread-grid-item'> <div class='ThreadNumber'> Post {$row['id']}<br> </div> <div class='UserOnThread'>{$row['Users']} </div> <h2>{$row['Title']} </h2> <button type='button' class ='collapse'>Hide</button> <div class ='img-block'> <img src={$row['$imageURL']}$imageURL alt='' /> </div> <div class='bodytextThread'> <p>{$row['ThreadBody']}</p> </div> </div> \n"; }?> <div class="comment-upload-box"> <form action="CommentUpload.php" method="post" enctype="multipart/form-data"> <table> <tr> <td></td> </tr> <tr> <td>Comment: </td> <td> <textarea name="CommentText" cols="100" rows="10" > Enter your posts... </textarea> </td> <td></td> </tr> <tr> <td></td> <td><input type="submit" name='submit' value="Submit"/></td> <td></td> </tr> </table> </form> </div> <div class='divTableForComments'> <div class='divTableBody'> <?php include 'dbconnect.php'; //Output Comments onto page //Create a variable for the Comment boxes so when clicking reply a text area shows $ChildCommentBoxes = "<div class='child-comment-upload-box' style='margin-left: 48px'> <form action='ChildCommentUpload.php' method='post' enctype'multipart/form-data'> <table> <tr> <td></td> </tr> <tr> <td>Comment: </td> <td> <textarea name='ChildCommentText' cols='100' rows='10' > Enter your posts... </textarea> </td> <td></td> </tr> <tr> <td></td> <td><input type='submit' name='submit' value='Submit'/></td> <td></td> </tr> </table> </form>"; $query = mysqli_query($conn, "SELECT * FROM Posts where IDOfThread=$number") or die (mysqli_error($conn)); while ($row = mysqli_fetch_array($query)) { //May need this later to output pictures // $imageURL = 'upload/'.rawurlencode($row["filename"]); $CommentText = nl2br($row['CommentText']) ; $ParentComment = "" ; $replies = "" ; if (empty($row['ParentId'])) { $ParentComment .= " <div class='divTableRow'> <div class='divTableCell'>{$row['User']} <div class='pointsincommentbox'> {$row['Upvotes']}points</div> <div class='divTableComment'> $CommentText <br> <div class='divCommentLinks'> <div class='upvotes'> ⬆</div> <div class='upvotes'> ⬇</div> <div> view comment </div> <div>report </div> <div>permalink</div> <button type='button' class ='CommentChildButton'>reply</button> <div class ='OpenChildCommentBox'> $ChildCommentBoxes </div> </div> </div> </div> </div> \n"; } echo "$ParentComment "; } ?> <div class ="sidebar"> </div> </body> </html> <script> var coll = document.getElementsByClassName("collapse"); var i; for (i = 0; i < coll.length; i++) { coll[i].addEventListener("click", function() { this.classList.toggle("active"); var content = this.nextElementSibling; if (content.style.display === "block") { content.style.display = "none"; } else { content.style.display = "block"; } }); } </script> <script> var coll2 = document.getElementsByClassName("CommentChildButton"); var i; for (i = 0; i < coll2.length; i++) { coll2[i].addEventListener("click", function() { this.classList.toggle("active"); var content = this.nextElementSibling; if (content.style.display === "block ") { content.style.display = "none"; } else { content.style.display = "block"; } }); } </script> And this is what it looks like I think I would probably change the margin of the responses to jut them in a bit and am thinking the best way would be to create a function that cycles through and where it finds a ParentId of a comment matching the Posts.id it would then put this beneath it? My comments are stored in a table titled Posts and Posts looks like
MariaDB [test]> describe Posts ; +---------------+-----------------+------+-----+---------------------+-------------------------------+ | Field | Type | Null | Key | Default | Extra | +---------------+-----------------+------+-----+---------------------+-------------------------------+ | id | int(6) unsigned | NO | PRI | NULL | auto_increment | | User | varchar(30) | NO | | NULL | | | PostTimeStamp | timestamp | NO | | current_timestamp() | on update current_timestamp() | | CommentText | varchar(8000) | YES | | NULL | | | IDOfThread | int(11) | YES | | NULL | | | Upvotes | int(11) | NO | | 0 | | | ParentId | int(11) | YES | | NULL | | +---------------+-----------------+------+-----+---------------------+-------------------------------+ 7 rows in set (0.002 sec)
|