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


  • 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 58 results

  1. List: collection which is ordered and changeable. But, if I create a list 'car' which is Unordered like that... car=["BMW","MAHINDRA","HERO","KTM"] print(car) SO, it does not support 'list' properties. But print result is ['BMW', 'MAHINDRA', 'HERO', 'KTM'] . Please help me that how it works even the 'list' is unordered, why it don't show any error message.
  2. Hi everyone, I am trying to set up the flexible with array, like set up the array by count the columns in tables in the Database, so I am still figure how to create variable word through loop to allow equalized from $_post as if $_post appear in two or three or four...I figured out to set up the $_post in loop, but I haven't find a way to have create new variable to equalized with $_post in loop in same time. here my code <!doctype html> <html> <head> <title>Add name and number</title> <link href="defaultdatabase.css" rel="stylesheet" type="text/css"> </head> <h2>Add any DSDJ information to database</h2> <?php require ("require2.php"); $sql = "show tables from NewDSDJ"; $list = mysqli_query($GaryDB, $sql); while ($row = mysqli_fetch_array($list)) { $table[] = $row[0]; $option = ''; foreach ($table as $rows) { $option .= "<option value='{$rows}'>{$rows}</option>"; } } ?> <form action="addname.php" method="post"> <table> <tr><th>Select the table</td><td> <select name="subject"> <?php echo $option; ?> </select></td><td><input type="submit" name="selected" value="select"></td></tr> </table> </form> <form> <table> <?php if (isset($_POST['selected'])) { $selected = $_POST['subject']; $column = "select column_name from information_schema.columns where table_name = '" . $selected . "'"; $list5 = mysqli_query($GaryDB, $column); while ($array = mysqli_fetch_array($list5)) { $input = ''; foreach ($array as $row5) { $input = "<tr><td>{$row5}:</td><td colspan='2'><input type='text' name='label[]'></td></tr>"; } echo $input; } if (isset($_POST['insert'])) { foreach ($array as $row6) { $ins = "{$row6},"; } for ($i = 0; $i < count($array); $i++) { $label = $_POST['label']; } echo $label; $insert = "insert into " . $selected . " (" . $ins . ") values (" . $label . ")"; mysqli_query($GaryDB, $insert) or die("Could not insert"); } }echo "<tr><td><input type='submit' name='insert'></td></tr>"; mysqli_close($GaryDB); ?> </table> </form> </html> Look at above of $insert, that is one I haven't figure how to create variable word to get data from name in form in HTML. Can you help? Thanks, Gary Taylor
  3. smus

    Array cloning

    Sorry for stupid question. I can't understand the purpose of cloning an array in JS. Why do we need it? What is the difference between: let a = []; let b = a; and: let a = []; let b = a.slice(0);
  4. I can not fix this script, because the output is not in sync. I have 3 arrays. 1) present column names. 2) prefix (fixed name). 3) suffix (uniqid value). Can someone explain how exactly I should create a foreach loop in a foreach loop with 3 arrays and fetching the field value from the get_result command as the the value it is related to. This would result in: <---->Present Column Name <-----> New Column Name <---->value1 <--------------------------------> value1_abcd <---->value2 <------------------------------> value2_abcd etc. <?php $prefix_arr = array( 'col_a' , 'col_b' ,'col_c' , 'col_d', 'col_e' , 'col_f' , 'col_g' , ) ; $col2 = uniqid(); $suffix = substr($col2, 5, 11); $servername = "localhost"; $username = "userx"; $password = "pass12345"; $dbname = "test_database"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $stmt = $conn->prepare("SHOW COLUMNS FROM table_xyz"); $stmt->execute(); $res = $stmt->get_result(); $pres_colname = $res; // var_dump($prefix_arr); foreach ($prefix_arr as $los_ele){ $prefix = $los_ele; // var_dump($prefix); // var_dump($suffix); $col_new = $prefix."_".$suffix; //var_dump($col_new); foreach ($pres_colname as $val){ $col = $val['Field']; // var_dump($col); ?> <br><input type="text" value =" <?php echo $col; ?>"><input type="text" value ="<?php echo $col_new;?>"> <?php $stmt = $conn->prepare("ALTER TABLE `table_xyz` CHANGE COLUMN `$col` `$col_new` VARCHAR(30) NOT NULL;"); $stmt->execute(); } } //$stmt->close(); $conn->close(); ?> The complicated thing this time is that I need the exact 'Field' value which is an output of get_result, so I can not fit it in.
  5. Hello, I have this array print: Array ( [0] => Array ( [name] => color [value] => red ) [1] => Array ( [name] => color [value] => blue ) [2] => Array ( [name] => color [value] => green ) [3] => Array ( [name] => age [value] => 16 ) ) I want to receive this result: Array ( [color] => Array ( [name] => color [value] => red, blue, green ) [age] => Array ( [name] => age [value] => 16 ) ) it works using the following php code: foreach ($feature_names as $row) { if (!isset($result[$row["name"]])) { $result[$row["name"]]["name"] = $row["name"]; $result[$row["name"]]["value"] = $row["value"]; } else { $result[$row["name"]]["value"] .= ", " . $row["value"]; } } How ever in PHP 7.1 using the code $result[$row["name"]]["name"] = $row["name"]; generates an error. Does someone know a work around? Thanks in advance!
  6. Ok bare with me because I have no idea what this is actually called. If someone knows I will update the title. I am working on a site that will act as an out-of-game marketplace for in-game items. I want to ensure that the player is within the zone of the market in-game so I need an easy way to generate an array of valid coordinates the player could be within to access the market. Ideally i would like to run a function with a parameter specifying the radius of a square and another of the player's current geoID. Basic geometry would help if the geoID's were, in my mind, easier to predict. here is problem: Going North: geoID's increase by 512 points Going East: geoID's increase by 1 Going South: geoID's decrease by 512 Going West geoID's decrease by 1 I realize this is more of a math question then PHP but I have no idea where to start to account for the odd increase. //Generate the exchangeArea array of a 5x5 square around the centeral id specified in param2. $exchangeArea = getExchangeArea(3,117053149); //if player geoID equals one of the values in the exchangeArea array return true else false function getExchangeArea(int radius, int geoID) { . . . } I have attached a graphic showing all the geoIDs for the above example. Ignore the geoAlt that is just they players Y axis. So there is no confusion, North on this diagram is the right side of the image. Making the top West. Any help on where to begin, even if its helping me identify keywords to search on for this kind of formula, algorithm, equation... what ever it's called, would be greatly appreciated.
  7. So I am working on a simple client database type program. I have a clients array that stores new clients that all have a first name, last name, phone number, etc... I also want the user to be able to add notes about their clients' family. So, one of the parameters of the client function is an array called familyNotes. Here is the code for this: function client(firstName, lastName, phoneNumber, address, hireDate, frequency, cost, entry, familyNotes) { this.firstName = firstName; this.lastName = lastName; this.phoneNumber = phoneNumber; this.address = address; this.hireDate = hireDate; this.frequency = frequency; this.cost = cost; this.entry = entry; this.familyNotes - familyNotes; } var laura = new client("laura", "simmerman", "1111111111", "laura rd", "01/01/01", "weekly", "100", "garage-1111"); var jana = new client("jana", "simmerman", "2222222222", "jana rd", "01/01/01", "weekly", "100", "garage-2222"); var clients = [laura, jana]; However, I do not know if the familyNotes array is working properly. I have a function that prompts the user to add a note about the family of a client, then adds the note to the array. Here is the code for this function: function addFamilyNotes(i) { var note = prompt("Add a note about the family: "); document.getElementById("familyNotes").innerHTML += "<li>" + note + "</li>"; clients[i].familyNotes.push(note); } I later have a function that is supposed to alert the length of the familyNotes array, however it doesn't alert anything currently. Here is the code: function familyNotesAlert(i) { alert(clients[i].familyNotes.length); } Does anyone know what I am doing wrong? Why is the alert not showing, and is anything actually being added to the familyNotes array?
  8. I was try make loop in loop with array. it should be like: L1: T1&C1---L1: T2&C2---L1: T3&C3--- L2: T1&C1---L2: T2&C2---L2: T3&C3--- L3: T1&C1---L3: T2&C2---L3: T3&C3--- But I got other than that i thought, so what did i wrong?
  9. Hello, I've just read the tutorial on how to process a form in PHP, available on this site, and I was wondering if there's a specific reason to declare empty variables (or arrays) at the beginning? I don't understand what is the point of doing so. For example, in the following code, why would the 2sd and 3rd lines be necessary? <?php $errors = []; $name = $email = $message = ''; if (condition) { $errors['name'] = 'alert'; } else { $name = sanitize_input($_POST['name']); if (new_condition, $name) { $errors['name'] = 'new alert'; } }
  10. Hi there, Been trying to learn PHP in my spare time the last few weeks. Setting myself little tasks, challenges, mini projects etc. but I'm quite stuck on this one. I'm trying to create an associative array to hold the following information on monthly rainfall in millimetres (jpeg of table attached below). I then want to find the minimum, maximum and average rainfall per month and per year. I've created two arrays experimenting but only the second one is associative (I've attached the php file below as well), but here is the code anyways... <?php $multidimensional_array = array(array("Jan", 292.9, 147.1, 175.9, 130.6, 107.7), array("Feb", 53.7, 154.9, 195.1, 91.1, 144.6), array("Mar", 92.8, 72.3, 87.2, 106.8, 64.4), array("Apr", 64.2, 55.4, 38.3, 63.6, 42.0), array("May", 135.3, 128.6, 90.4, 111.2, 45.4), array("June", 37.1, 63.4, 40.5, 27.2, 68.0), array("July", 76.5, 31.6, 35.8, 82.7, 66.9), array("Aug", 97.1, 153.8, 90.0, 93.4, 107.4), array("Sep", 39.2, 16.1, 72.4, 87.9, 88.5), array("Oct", 57.6, 125.2, 105.2, 49.7, 35.3), array("Nov", 184.4, 154.4, 129.3, 190.5, 69.2), array("Dec", 274.3, 100.7, 110.2, 233.2, 74.0), ); $multidimensionalAss_array = array( array("month"=>"Jan", "2012"=>92.9, "2013"=>147.1, "2014"=>175.9, "2015"=>130.6, "2016"=>107.7), array("month"=>"Feb", "2012"=>53.7, "2013"=>154.9, "2014"=>195.1, "2015"=>91.1, "2016"=>144.6), array("month"=>"Mar", "2012"=>92.8, "2013"=>72.3, "2014"=>87.2, "2015"=>106.8, "2016"=>64.4), array("month"=>"Apr", "2012"=>64.2, "2013"=>55.4, "2014"=>38.3, "2015"=>63.6, "2016"=>42.0), array("month"=>"May", "2012"=>135.3, "2013"=>128.6, "2014"=>90.4, "2015"=>111.2, "2016"=>45.4), array("month"=>"June", "2012"=>37.1, "2013"=>63.4, "2014"=>40.5, "2015"=>27.2, "2016"=>68.0), array("month"=>"July", "2012"=>76.5, "2013"=>31.6, "2014"=>35.8, "2015"=>82.7, "2016"=>66.9), array("month"=>"Aug", "2012"=>97.1, "2013"=>153.8, "2014"=>90.0, "2015"=>93.4, "2016"=>107.4), array("month"=>"Sep", "2012"=>39.2, "2013"=>16.1, "2014"=>72.4, "2015"=>87.9, "2016"=>88.5), array("month"=>"Oct", "2012"=>57.6, "2013"=>125.2, "2014"=>105.2, "2015"=>49.7, "2016"=>35.3), array("month"=>"Nov", "2012"=>184.4, "2013"=>154.4, "2014"=>129.3, "2015"=>190.5, "2016"=>69.2), array("month"=>"Dec", "2012"=>274.3, "2013"=>100.7, "2014"=>110.2, "2015"=>233.2, "2016"=>74.0), ); //print_r($multidimensional_array); print_r($multidimensionalAss_array); ?> Could anyone give me some advice on where I'd go next with the associative array? I'm fairly sure I can't loop through it no? I'm fairly stuck on this and it's annoying me quiet a bit! Finding JavaScript easier to learn for sure... haha Thanks, Fintan table challenge.php
  11. How to get an array index by its value (key)? Is there a special function for that in PHP? For example, I have an array $a ["zero","one","two"] and a variable $b = "two", I know the value is in the array, but I don't know its index.
  12. So this generates 3 arrays with 5 numbers in each one. How would I go about checking each array to see if there are any duplicate numbers in an array?
  13. I found an online function called GetDays and I slightly modified it to calculate the number of days between a past date and the current time. The function works fine for 1 input, but I have a table full of records and want to use the function to get the total days for each record separatedly. <?php // function GetDays($sStartDate, $sEndDate){ // Firstly, format the provided dates. // This function works best with YYYY-MM-DD // but other date formats will work thanks // to strtotime(). $sStartDate = gmdate("Y-m-d", strtotime($sStartDate)); $sEndDate = gmdate("Y-m-d", strtotime($sEndDate)); // Start the variable off with the start date $aDays[] = $sStartDate; // Set a 'temp' variable, sCurrentDate, with // the start date - before beginning the loop $sCurrentDate = $sStartDate; // While the current date is less than the end date while($sCurrentDate < $sEndDate){ // Add a day to the current date $sCurrentDate = gmdate("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate))); // Add this new day to the aDays array global $aDays; // deze global heb ik zelf toegevoegd en MOET hier staan, iig niet buiten deze conditie global $tot_days; $aDays[] = $sCurrentDate; } $tot_days = count($aDays); $tot_days = $tot_days +1; return $tot_days; } // function ends // // here the records are fetched from the database table while($row = $result->fetch_assoc()){ echo "<center>"; $array = implode(" / " , $row); $sStartDate = $row['created_on']; $sEndDate = date("Y-m-d"); GetDays ($sStartDate, $sEndDate); echo "</center>"; ?> <center> <form action="#" method="post" > <input type="text" name="test" value="<?php echo $array . ' / ' . $sEndDate . ' / ' . $tot_days ; ?>" size="60"/> </center> <?php } // rest of the code to complete the form --> ?>
  14. 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
  15. I am working on a project for my job. I have php that creates multiple radio button lists through an array. There are 6 categories that that a list of radio buttons for each of the categories. I am trying to add an onclick javascript function to just one of the radio buttons. There is a text box on the very bottom, I want that to only show up if a certain radio button is clicked. I have the code attached below <?php $form_fields = array( "id" => array( "bsc_id", "fname", "mname", "lname", "email", "grad_id", "major_id", "grad_date", "deg_id", "age_id", "ethn_id", "res_id", "assist_id", "assist_other" ) , "name" => array( "Banner ID", "First Name", "Middle Name", "Last Name", "E-mail Address", "Status", "Major", "Graduation Date<br/>(mm-yyyy)", "Degree", "Age Group", "Ethnicity", "Residency", "Greatest Assistance", "If Assistance Other" ) , "type" => array( "age_id" => "radio", "grad_id" => "radio", "major_id" => "select", "deg_id" => "radio", "ethn_id" => "radio", "grad_date" => "date", "res_id" => "checkbox", "assist_id" => "radio" ) , "option" => array( "age_id" => "sql:select * from age_code", "grad_id" => "sql:select * from grad_code", "major_id" => "sql:select * from major_code ORDER BY major_text", "deg_id" => "sql:select * from deg_code", "ethn_id" => "sql:select * from ethn_code", "grad_date" => "fields:m-Y", "res_id" => "sql:select * from res_code", "assist_id" => "sql:select * from assist_code" ) );
  16. Down here the code to call a function it works with list. I dont understand how list works, In my example list gives a survey of 2 arrays that are executed inside the function here is how I call the function: $row = list ($variable, $number) = my_function(); var_dump($row); the output is like this: I need the values separated but how can I list the second array (the one with the numbers) as single numbers outside an own function?
  17. My goal is to loop with foreach through two variables. So I found this script; <?php $abc = array('Mark','Laura'); $add = array('cocktails','champagne'); $array = array($abc,$add); foreach ($array as list($arr1, $arr2)) { // echo '<br>'; echo '<br>'; echo $arr1; echo '<br>'; echo $arr2; } But the output is not wat is desired. It says: And I would rather have: Is there any function / command in the php array reference to do this or should other code be used?
  18. Hello, I'm currently learning JavaScript and I plan to work a lot with arrays. I store all arrays in external files and use JSON to access them. Now I wanted to read the names of all arrays that are nested in one main array to create a navigation list but I don't know how to do that. This is an example of a JSON file I use: {"MainArray":[ {"SubArray1":[{ ... }] }, {"SubArray2":[{ ... }] }, {"SubArray3":[{ ... }] } ]} How do I get the names of all SubArrays? I tried this // arr is a JSON-parsed string function myFunction(arr) { var out = ""; var i; for(i = 0; i < arr.MainArray.length; i++) { out += arr.MainArray[i].toString() + '<br>'; } document.getElementById("aso").innerHTML = out; } but it only creates a list of "[object Object]" items. Should I create another JSON file where all array names are listed instead?
  19. I used AJAX to retrieve concatenated data from a XML document. Now I need to store that data into a Javascript array. How do I do this? My Javascript Code: var SVG_Data var Retrieved_Data var Coordinate_Pair var Element_List var Counter function Setup() { SVG_Data = new XMLHttpRequest(); SVG_Data.open("GET","http://localhost:8080/exist/rest/db/apps/HTML_Student/Database_Retrieval.xq", true); SVG_Data.onreadystatechange = function () { if (SVG_Data.readyState = 4) { Retrieved_Data = SVG_Data.responseText; document.getElementById("Information").value = Retrieved_Data; Coordinate_Pair = new Array(); Coordinate_Pair.push.apply(Retrieved_Data); Element_List = new Array("Top_Ladder_Line","Middle_Ladder_Line", "Bottom_Ladder_Line"); for (Counter = 0; Counter < 3; Counter++) { document.getElementById("Information").value = Coordinate_Pair[Counter]; document.getElementById(Element_List[Counter]).setAttribute("points", Coordinate_Pair[Counter]);} } } SVG_Data.send(); } The concatenated data I received from the eXist database: "60,30 60,80 150,80 150,30", "60,130 60,80 150,80 150,130", "60,180 60,130 150,130 150,180"
  20. I have: function val(a,z){ return a/2, z+8; } val(3,4); Put this in a Array; x = 1,5 y = 12 [x,y]; Thanks.
  21. The idea is to insert with the browser a multiple input field, a loop, into mysql database. Is the solution to first put this loop input variable in an array and after that create in this case multible tables? Or is an array not necessary?
  22. I want to add elements by the browser into an array with the name $map I wrote the next piece of code for this: <?php $var = $_POST["var"]; function addIntoArray($var) { global $map; if (($var != ".") || ($var != "..")) { array_push($map, $var); echo $var . " succesfully added to the array!"; } return; } ?> The problem though, is not having an error code, but the screen just does not give an output at all while I did make an echo line. Whats going wrong here?
  23. Zerivo

    Array problem

    Hello i try make it like: <html><head> <script type="text/javascript"> function Code() { A=["T1","T2","T3",4,2,1]; var B1=A;var B2=A;var B3=A; if (A[0]=="T2") {B1[3]=5;} if (A[1]=="T2") {B2[3]=5;} if (A[2]=="T2") {B3[3]=5;} document.getElementById('W1').innerHTML="B1:"+B1[3] document.getElementById('W2').innerHTML="B2:"+B2[3]; document.getElementById('W3').innerHTML="B3:"+B3[3]; } </script></head><body> <input type="button" value="Code it!" onClick="Code()"><br><br><br> <div id="W1"></div> <div id="W2"></div> <div id="W3"></div> </body> when i press button then i got 5 on all B1, B2 and B3. but it should be only B2 have 5 while other got 4. Why it going wrong?
  24. Alright, so I am making a program that when a button that says "yo" for example, will display a prompt when click. If the answer to the prompt is a verb, then the "yo" form of that verb is displayed. So far I have a button, that when clicked has a prompt. When I enter a word in the button I can't make it display the "yo" form of the verb. Please help: Here is my javascript: function verb(verb, yo) { this.verb = verb; this.yo = yo;}//*All verbsvar estar = new verb("estar", "estoy");//*All arraysvar verbs = [estar];//*Verb translation present_yofunction presentYo(){ var verb = verbs; var answer = prompt("Enter a verb: ").toLowerCase(); if (answer == verb){ document.getElementById("translation").innerHTML = "verbs.yo"; } else{ document.getElementById("translation").innerHTML = "I do not know the translation."; } } When I enter a word, all that shows up is "I do not know the translation." Please help. Thanks.
  25. Hello so I made an array and it works fine when you refresh the page the image changes but at lower screen resolutions the image cuts of the edge. With my basic code it worked fine I was wondering what I was doing wrong. This was my old code which was just one image and at lower resolutions it would still fit on the screen <center><img src="my image url" width=47%> </center> But when I use my array it cuts of I want to make the image center and just put width=47% like the top code but not sure where to put it <script language="JavaScript"><!--function random_imglink(){var myimages=new Array()myimages[1]="my image url"myimages[2]="my image url"myimages[3]="my image url"myimages[4]="my image url"myimages[5]="my image url"myimages[6]="my image url"var ry=Math.floor(Math.random()*myimages.length)if (ry==0)ry=1document.write('<img src="'+myimages[ry]+'" width=47%')}random_imglink()//--></script> If you could help me it would be much appreciated
  • Create New...