Jump to content

Search the Community

Showing results for tags 'Sort'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Found 12 results

  1. Hi I am new to javascript and was creating search suggestions referring to the article on https://www.w3schools.com/howto/howto_js_filter_lists.asp , but the search suggestions in output are not sorted. Can someone guide me on updating this code to get alphabetically sorted suggestions? Thanks in advance
  2. Hi everybody http://www.w3schools.com/js/js_array_sort.asp If I'm right, the JS-Tutorial about sorting arrays randomly has a lack. The order of the array is kind of in a random order at the first glance, but the elements often stay at the same place as they were. This is true in the most for the element at the end of the array and the effect happens in most browsers, but not in all of them. I've written a script to test this. In these browsers the elements are not evenly distributed as they should: Chrome, IE, Edge, Opera. In Safari they were evenly distributed when I tried it. Try it yourself. <!DOCTYPE html> <html> <body> <p id="demo"></p> <script> var sum; var points; var i, j; sum = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; for (i=0;i<1000;i++){ points = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]; points.sort(function(a, {return 0.5 - Math.random()}); for (j=0;j<points.length;j++){ sum[j]+=points[j]; } } document.getElementById("demo").innerHTML = sum; </script> </body> </html> What the code does: It creates an array with a leading 1 and a 1 at the last place and zeroes between (points). Then it sorts this array randomly and adds the resulting array to a sum array. Then it starts again with the specific array. The generating, sorting and adding is done a 1000 times. When you reload the page the summed up numbers are displayed. Result: In many browsers the last number is higher than the others, which shouldn't happen with correct random sorting. Cheers, celus
  3. Hello All, I am stuck trying to filter results of a json response. I have a sample json response: [ { "id":0, "commentText":"Test", "createdBy":"User1", "isImportant":false }, { "id":1, "commentText":"Hello World", "createdBy":"User2", "isImportant":true }, { "id":2, "commentText":"Testing", "createdBy":"User2", "isImportant":false }, { "id":3, "commentText":"This is another one", "createdBy":"User2", "isImportant":true }, { "id":4, "commentText":"Hello World!", "createdBy":"User2", "isImportant":true } ] I am attempting to filter out results that "isImportant" are not true. I have tried multiple ways of doing it with no luck. IE. var response = $(jsonSample).filter(function (i,n){ return n.isImportant===true }); var response2 = $.grep(Object(jsonSample), function(j){ return j.isImportant !== false; }); var response3 = $.map(jsonSample, function (n,i){ $.each(n, function(j){ return n.isImportant !== false; }) }); console.log(response); //jquery-2.2.4.min.js:2 Uncaught Error: Syntax error, unrecognized expression: ... console.log(response2); //logs every individual character in the jsonSample ["[", "{", """, "i", "d", """, ":", "1", ... console.log(response3); //jquery-2.2.4.min.js:2 Uncaught TypeError: Cannot use 'in' operator to search for 'length' in ...
  4. Hello, I'm trying to make some kind of leaderboard, such as the example below: var game = ["Dominoes",95,"Cards",22,"Chess",65]; The idea is to try to group all of the numbers together in the array so that I can return a position on them. For example: 95 - would return 1st place (for the most points) 65 - 2nd place 22 - 3rd place But the numbers in the "game" variable would also need to be linked in with the games so that if they were sorted numerically then the games would follow suit as well. Would anyone be able to help with this, please? I'd be grateful for any assistance. Many thanks,Dan.
  5. Zerivo

    Sort Table

    Hi i need help for make sort table I want to sort on table, like Shop name, sell type and location etc so if i press button sort location then sort a-z from top to bottom. how i can do it? like it: <table border="1"> <tr><td>Shop name</td><td>Type shop</td><td>location </td></tr> <tr><td>The Common Defense</td><td>Armor Shop</td><td>New Sorpigal</td></tr> <tr><td>The Eagle's Eye</td><td>Weapon Shop</td><td>Castle Ironfist</td></tr> <tr><td>Smoke and Mirrors</td><td>Alchemist Shop</td><td>Mire of Damned</td></tr> </table> so, how i sort those? i try find but hard to found right code.
  6. etsted


    i have created a guestbook for my website, but everytime i add a comment it just put the comment below the other. I want it so that the first page only shows maybe 35 comments, then a new page will be created and then 35 comments can be placed there etc. echo "<h1>guestbook</h1>"; echo "<hr />"; $form = " <form action='index.php' method='POST'> <table> <tr> <td>name:</td> <td><input type='text' name='name' /></td> </tr> <tr> <td>message:</td> <td><textarea rows='5' cols='30' name='message'></textarea></td> </tr> <tr> <td></td> <td><input type='submit' name='submit' /></td> </tr> </table> </form> "; include "connect.php"; $getdata = mysql_query("SELECT * FROM guestbook ORDER BY id DESC"); while($row = mysql_fetch_assoc($getdata)) { $id = $row['id']; $name = $row['name']; $message = $row['message']; $date = $row['date']; $message = nl2br($message); echo " <table> <tr> <td><strong>lastet opp av $name. Dato: $date</strong></td> </tr> <tr> <td>$message</td> </tr><br /> </table> "; } echo "<hr />"; $submit = $_POST['submit']; if($submit) { $name = $_POST['name']; $message = $_POST['message']; if($name && $message) { include "connect.php"; $query = mysql_query("SELECT * FROM guestbook WHERE name='$name' && message='$message'"); $numrows = mysql_num_rows($query); if($numrows == 0) { mysql_query("INSERT INTO guestbook VALUES('','$name','$message',CURDATE())"); echo "du har sent en melding $form"; } else { echo "du kan ikke sende den samme meldingen om igjen $form"; } } else { echo "du må fylle ut skjemaet $form"; } } else { echo $form; } ?>
  7. Hello guys, i need some experienced info here.. i need to sort selected data, thats why i used case like: SELECT * FROM Customers ORDER BY CASEWHEN CustomerName LIKE '%a%' THEN 1WHEN CustomerName LIKE '%b%' THEN 2ELSE 3END Everythings fine here, but I need to sort each sector (1, 2 and 3) seperately by CustomerName`s lenght. How to do that? any ideas ?
  8. Hey everyone here is what i have so far..... <?php$posts = get_posts('numberposts=10&order=DESC&category=68&orderby=post_title');foreach ($posts as $post) : start_wp(); ?><?php echo "<hr>"; ?><?php echo the_event_end_date( $id, $showtime, $dateFormat); ?><?php echo "<hr>"; ?><?php the_title(); ?><?php the_excerpt(); ?><?phpendforeach;?> I need the the_excerpt and the the_title to sort in order from soonest to later. (event happening soonest to the one happening later that year)This code the_event_end_date( $id, $showtime, $dateFormat); displayed the event date in this format....June 16, 2013How can i sort this I am out of ideas???PLz HELP!!!!http://wordpress.org/extend/plugins/the-events-calendar/
  9. I have an array full of smaller arrays. The smaller arrays contain elements, one of which is a date. (Not a timestamp, a date such as 1, 2, 3, etc.) I want to sort the small arrays within the large array in order of this date. I don't see anything in the docs for PHP on how to do this.Let me state this another way. I have an array called $eventsThisMonth. I would like to sort $eventsThisMonth by $eventsThisMonth[every][dateOfThisOccurrance]. Thank you in advance for your great help and advice. Jeff P.S. I tried sorting "manually" using an outside loop that goes 1-31 (for the possible values of the date) and an inner loop that goes 0-count($eventsThisMonth) and compares the dateOfThisOccurrance of each smaller array to the index of the outside loop. If equal, it does an array_push to another array. This still didn't work; the other array was in the same order as the original.
  10. Hi there!!W3schools has demonstrated how to sort a numerical array using the following code: <code><script type="text/javascript">function sortNumber(a, {return a -b;}var arr = new Array(6);arr[0] = "10";arr[1] = "5";arr[2] = "40";arr[3] = "25";arr[4] = "1000";arr[5] = "1";document.write(arr + "<br />");document.write(arr.sort(sortNumber));</script></code>I just wanted to know how does the sortNumber() function work? What's the meaningful of the a,b parameters which are passed into the function? What are they intended to represent, and how does this snippet: a-b cause to sort the array numerical elements ascending?
  11. Hi everybody, First post here, hoping someone can help. I'm looking for a way to specify a primary and secondary column to sort by in a table. For example, a list of people that are to be contacted in an emergency, some of whom are "Primary" contacts, and some who are "Alternate" contacts. What I want is for the primaries to be listed first, in alphabetical order, before any alternates, who are also listed alphabetically. (Primary and Alternate have also been assigned a numerical value, with Primary being 1 and Alternate being 2.) Currently, these table sort only on one node, the person's name, so I get: Type Name1. Primary Ben Smith2. Alternate David Willis2. Alternate Mary Jones1. Primary Robert Crane What I want is: Type Name1. Primary Ben Smith1. Primary Robert Crane2. Alternate David Willis2. Alternate Mary Jones The values are being pulled from database software where each field (i.e. "Type" or "Name") has a Field ID that the XSLT uses to populate the output document. Code looks like this right now: <table> <tbody> <tr> <th>Type</th> <th>Name</th> </tr> <xsl:for-each select="Record/Field[ID='8132']"> <xsl:sort select="../Field[ID='8131']/Value"/> <tr> <td><xsl:value-of select="../Field[ID='8132']/Value"/></td> <td><xsl:value-of select="../Field[ID='8131']/Value"/></td> </xsl:for-each> </tr> </tbody></table> '8132' is the Type field, '8131' is the Name field. Hope I've explained this clearly. Thanks in advance for any assistance!
  12. I have an asp form where a user can select their campus and class section. I want to use their answers (variables) in the xsl file to pull only those options from the xml file. Anybody have an idea of how to make this work? Here is my xsl file: <?xml version="1.0" encoding="utf-8"?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <table cellpadding="5" cellspacing="0" border="1"> <thead> <tr> <th>Class</th> <th>Type</th> <th>Day</th> <th>Time</th> <th>Tutor</th> <th>Location</th> </tr> </thead> <tbody> <xsl:for-each select="schedule/course[@section='<% response.write(section) %>' and @campus='<% response.write(campus) %>']"> <xsl:sort select="class" order="ascending"/> <tr> <td><xsl:value-of select="class"/></td> <td><xsl:value-of select="type"/></td> <td><xsl:value-of select="day"/></td> <td><xsl:value-of select="time"/></td> <td><xsl:value-of select="tutor"/></td> <td><xsl:value-of select="location"/></td> </tr> </xsl:for-each> </tbody> </table> </xsl:template></xsl:stylesheet> this is my asp file <%dim campus, sectioncampus = request.form("campus")section = request.form("section")'Load XMLset xml = Server.CreateObject("Microsoft.XMLDOM")xml.async = falsexml.load(Server.MapPath("tutor.xml"))'Load XSLset xsl = Server.CreateObject("Microsoft.XMLDOM")xsl.async = falsexsl.load(Server.MapPath("tutor.xsl"))'Transform fileResponse.Write(xml.transformNode(xsl))%>
  • Create New...