473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

problem with arrays

chelvan
90
hi
forum



i've an array, which read the data values from the database. now i need to pass this array into javascript. is it possible? how is it?

thanks

chel-1
Sep 26 '08 #1
4 1096
ak1dnar
1,584 Expert 1GB
I think you need to pass generated php array elements to a javascript array right? Have a look here, Its just an example to do the job. Hope this helps.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $lang = array("PHP", "C++", "Python");
  3. var_dump($lang);
  4. ?>
  5. <html>
  6. <head>
  7. <script type="text/javascript">
  8. function myFunction(){
  9. var myArray = new Array();
  10.  
  11.     <?php
  12.         foreach($lang as $key  => $value) {
  13.     ?>
  14.          myArray[<?php print $key?>] = "<?php print $value?>";
  15.  
  16.     <?php
  17.     }
  18.     ?>
  19.  
  20. for (var i=0; i<myArray.length; i++) {
  21.  alert(myArray[i]);
  22. }
  23. }
  24. </script>
  25.  
  26. </head>
  27.  
  28. <body onLoad="myFunction()">
  29. </body>
  30. </html>
  31.  
Sep 26 '08 #2
chelvan
90
I think you need to pass generated php array elements to a javascript array right? Have a look here, Its just a example to do the job. Hope this helps.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $lang = array("PHP", "C++", "Python");
  3. var_dump($lang);
  4. ?>
  5. <html>
  6. <head>
  7. <script type="text/javascript">
  8. function myFunction(){
  9. var myArray = new Array();
  10.  
  11.     <?php
  12.         foreach($lang as $key  => $value) {
  13.     ?>
  14.          myArray[<?php print $key?>] = "<?php print $value?>";
  15.  
  16.     <?php
  17.     }
  18.     ?>
  19.  
  20. for (var i=0; i<myArray.length; i++) {
  21.  alert(myArray[i]);
  22. }
  23. }
  24. </script>
  25.  
  26. </head>
  27.  
  28. <body onLoad="myFunction()">
  29. </body>
  30. </html>
  31.  
thanks its ok.
but if i create the array from reading the database what will happen. is the above code is ok or am i need to change?

chel-1
Sep 26 '08 #3
ak1dnar
1,584 Expert 1GB
As I said Its an example to do the job. You have to do the changes as required. Good luck!
Sep 26 '08 #4
chelvan
90
As I said Its an example to do the job. You have to do the changes as required. Good luck!

thanks ak1dnar.
i try and come back again.



thanks
chel-1
Sep 26 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Fnark! | last post by:
I am creating a shopping cart using PHP Version 4.1.2. I am creating and registering a cart object in a session. The cart object contains an array of arrays called $order whose elements are a...
2
by: Xarky | last post by:
Hi, I have a two dimensional array as follows: double myArray = new double; Now I have a method which is returning double, which is of size 41. I need to put the data of the array returned...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
1
by: codergem | last post by:
The following code is for heap sort but its not working properly. According to my analysis the Logic is correct but still its not showing the correct output. Thanks. #include "stdafx.h"...
4
by: sonjaa | last post by:
Hi last week I posted a problem with running out of memory when changing values in NumPy arrays. Since then I have tried many different approaches and work-arounds but to no avail. I was...
3
by: MariyaGel | last post by:
I have wrote the program and it worked fine until I had to include one more array into it. As you can see below the two arrays of volume and mass are working properly now I need to include a third...
9
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But...
19
by: rmr531 | last post by:
First of all I am very new to c++ so please bear with me. I am trying to create a program that keeps an inventory of items. I am trying to use a struct to store a product name, purchase price,...
43
by: John | last post by:
Hi This .net is driving me crazy!! In VB6 I had a type which contained a couple of multi-dimentional arrays which i used to create and read records: Type AAA : Array1(10,10,2) as Integer
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.