Jump to content

Search the Community

Showing results for tags 'array'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

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

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 57 results

  1. Hi,Apologies if I'm doing something very obviously stupid here, I'm fairly new to this sort of thing. What I'm basically trying to do is crop a two dimensional array of coordinates to the same length as another array called from an sql database using php and then made useable in javascript via json_encode. The good news is that I've managed to accomplish this. The code below actually does this twice with the database information called in different orders so that I have two two-dimensional javascript arrays, each with an x and y coodinate tagged onto the end of each row. (For anyone who's interested in the whys and wherefores, the database contains information abpout different image galleries (title, description, thumbnail etc). I'm going to be using these two arrays along with jquery animate to allow visitors to the site to change the order in which thumbnails are displayed based on date gallery updated or gallery size). This all sort of works fine. There are a couple of functions, 'prune' which is the parent function (I think I'm using the terminology correctly) and two similar but separate 'populateArray' functions (1 and 2). The trouble is that the two inner functions don't seem to want to return a value. I can access the two arrays from within the populateArray functions but as soon as I try to return the values (as 'galDate' and 'galSize') I get nothing. Code is laid out below. Like I say, apologies if I'm making a really basic mistake here but I'm completely stumped and could do with a nod in the right direction. Thanks in advance.Stef <script>var sqlData1 = (<?php print json_encode($sqlData1);?>);var sqlData2 = (<?php print json_encode($sqlData2);?>); var coordinates = [['100px','100px'],['100px','200px'],['100px','300px'],['200px','100px'],['200px','200px'],['200px','300px'], ['300px','100px'],['300px','200px'],['300px','300px'],['400px','100px'],['400px','200px'],['400px','300px'],['500px','100px'],['500px','200px'],['500px','300px']]; //Function to make arrays the same length function pruneArrays(sqlData1,sqlData2, coordinates){ for(i=(coordinates.length-sqlData1.length); i>0; i--){ coordinates.pop(coordinates); } populateArray1(sqlData1, coordinates); populateArray2(sqlData2, coordinates); return();} //Function to create date ordered array with coordinatesfunction populateArray1 (sqlData1, coordinates){ for(i=0; i<sqlData1.length; i++){ for(j=0; j<(sqlData1.length-1); j++){ sqlData1.push(coordinates[j]); } } var galDate = sqlData1; //document.write(galDate); - if this line is active 'galDate' displays no problem //document.write ("<br /><br />"); return (galDate);} //Function to create size ordered array with coordinatesfunction populateArray2 (sqlData2, coordinates){ for(i=0; i<sqlData2.length; i++){ for(j=0; j<(sqlData2.length-1); j++){ sqlData2.push(coordinates[j]); } } var galSize = sqlData2; //document.write(galSize); - if this line is active 'galSize' displays no problem return (galSize);} document.write(pruneArrays(sqlData1, sqlData2, coordinates));// The line above however, doesn't return anything.</script>
  2. rogerg

    Problem With Array

    Hello, I would like to do some calculations in a predefined array. With the script below I can retrieve a number of the matrix.However, I want to reuse this number and do some calculations with it, for example calculate the factorial. But I don't now how I have to save the selected number and then to reuse it for further calculation. can you help me? Thx,Roger <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head><title>MATRIX</title> </head><body><p>MATRIX</p><form action=''><table> <tr><td>Size:</td><td><input type='text' id='size' value='' /></td></tr> <tr><td>Line:</td><td><input type='text' id='line' value=''/></td></tr> <tr><td>Col:</td><td><input type='text' id='col' value=''/></td></tr> <tr><td>Selected:</td><td><input type='text' id='selected' value=''/></td></tr></table></form> <input value="show" type='button' onclick="see(document.getElementById('size').value/1, document.getElementById('line').value/1,document.getElementById('col').value/1)"/></div> <script>function matrix(a){ var myMatrix=new Array(); var value=1; for(var i=0; i<a; ++i){ myMatrix=new Array(); for(var j=0; j<a; j++){ myMatrix[j]= value; ++value; } }return myMatrix;}function see(x,y,z){ if(y>x-1 || y<0){ document.getElementById('selected').value="Error"; document.getElementById('line').className='error'; document.getElementById('line').value="Number between 0 and "+(x-1)+" please!"; } else if(z>x-1 || z<0){ document.getElementById('selected').value="Error"; document.getElementById('col').className='error'; document.getElementById('col').value="Number between 0 and "+(x-1)+" please!"; } else{ myMatrix=matrix(x); document.getElementById('line').className='correct'; document.getElementById('selected').value=myMatrix[y][z]; }}</script></body></html>
  3. westman

    Array Simple Get Data

    i have a 6 number array separated by (,)for example4,29,70,17,49,51,how do i get my random 6 numbers out the array?i tried...$the_number = explode(",", $number);$number1 = array_slice($the_number, 0, 1);$number2 = array_slice($the_number, 0, 2);$number3 = array_slice($the_number, 0, 3);$number4 = array_slice($the_number, 0, 4);$number5 = array_slice($the_number, 0, 5);$number6 = array_slice($the_number, 0, 6);and it did not work
  4. I'm trying to write an algorithm return an array sorted by a given property in a JSON object. Here's an example of what I want to sort: obj_to_be_sorted = {'four' : {'num' : 4},'one' : {'num' : 1},'three' : {'num' : 3},'two' : {'num' : 2}} sort = function(obj, property, reverse_order) { a = [] for (key in obj) { a.push(key) } return a.sort(a, { /* I think it would involve the sort function... */ }} sorted_array = sort(obj_to_be_sorted, 'num', false); // should return the JSON keys sorted by the 'num' property, i.e. ['one', 'two', 'three', 'four'] I just don't know I would go about doing this. I'm thinking it would be only a few lines of code - very simple - but I'm just not good at writing algorithms yet. I would greatly appreciate any assistance you could give me.
  5. tinfanide

    Php Array And For Loop Problem

    <?php$sites = array(array(array("Google","http://www.google.com"), array("search engine","platform","news","weather") ), array(array("Youtube","http://www.youtube.com"), array("search engine","platform","news","video") ) ); $query = $_GET["query"];if (strlen($query) > 0) {$suggestions = "";for ($i=0; $i<count($sites); $i++) { if (strtolower($query) == strtolower(substr($sites[$i][0][0],0,strlen($query)))) { for ($j=0; $j<count($sites[$i][1]); $j++) if ($suggestions == "") { $suggestions = "<a href=".$sites[$i][0][1]." target='_blank'>".$sites[$i][0][0]."</a>"."<br />".$sites[$i][1][$j]; } else { $suggestions += " , "."<a href=".$sites[$i][0][1]." target='_blank'>".$sites[$i][0][0]."</a>"; } } }}if ($suggestions == "") {$response = "no suggestion related to your query: ".$query;} else { $response = $suggestions; }echo $response;?> I want when users search for the first array, it also displays the third array array("search engine","platform","news","weather") But I seem to fail to use a for loop inside another for loop. Any fix for that?
  6. I am having problems with getting the right syntax in Javascript to access and array set up in a form (for check boxes) via getElementById The setup on the form works fine because I can access it in PHP no problem. But can't get the syntax right in JS setup in PHP as followes while($row = mysql_fetch_row($result)) { print "<input type ='checkbox' class = 'selectedsurvey' id = 'SelectedSurveys[".$x."]' name = 'SelectedSurveys[".$x."]' checked='checked'/>"; print "<label>$row[1]</label>"; print "<br/>\n"; $x+=1; } They are read from a database of surveys My code in JS for(i=0;i<numberofsurveys;i++){ test = document.getElementById("SelectedSurveys"[i]); if (test.value == "on") { errmsg = errmsg + "'" + test.value + "',"; anychecked = true; } }if (!anychecked){ errmsg=errmsg+"Error: A site must contain at least 1 survey.<br/>"; } Any help much appreciated. PS test is already defined in a var earlier.
  7. honkmaster

    Help With Array

    Hi, can anyone help me with this. I have a column in my table call "machine", I want to count the number of time each appears and return the results into an array In the example below the number of times each printer appears in the column is returned to the array Cheers Chris ____________machine____________fb75001fb75002turbojet turbojet xl15001xl15002canonroland $fb75001 = '1';$fb75002 = '1';$turbojet ='2';$xl15001 = '1';$xl15002 = '1';$canon = '1';$roland = '1'; $query = "SELECT machine, COUNT(machine) FROM maindata GROUP BY machine";
×