473,803 Members | 3,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

converting php variables into javascript

25 New Member
Apache2 over XP Home, PHP5, PostgreSQL8.2
If this is not the correct forum for this, it can be reposted accordingly.
I have php variables/arrays that I want to display in a php webpage. What I am doing is using my server-side php script to generate javascript and convert my php data. The 1st bit of code is my php script, the 2nd is my javascript from my php webpage. I have 2 variables $numrows and $numfields, and 2 arrays $fieldname[] and $parts[][] (hopefully self-explanatory). In my php webpage I am using javascript to display a table with the converted values. You will notice in my javascript that numrow is used after numfield, yet its numfield that is showing as undefined. I am calling DisplayCustomer s from my xmlhttprequest. Are there any Javascript/PHP people who can help my with this? Am I going into a dead end with this? Any advice/comments welcome!

rpjd.

php script
[php]
<?php
$connect=pg_con nect("dbname=Da tabaseName host=localhost user=User password=passwo rd");
if (!pg_connection _busy($connect) )
{
$result=pg_quer y$connect, "select * from customer;");
}
$numrows=pg_num rows($result);
$numfields=pg_n um_fields($resu lt);
echo "<script language=\"Java script\">\n";
echo "var numrows = new var;\n";
for ( $numrows as $key => $numrow)
{
echo "numrows[\"$key\"] = \"$numrow\";\n" ;
}
echo "</script>\n";
echo "var numfields = new var;\n";
for ( $numfields as $key => $numfield)
{
echo "numfields[\"$key\"] = \"$numfield\";\ n";
}
echo "</script>\n";
$customers[][] = array("name" => "", "address" => "", "contact_no " => "");
for($i=0;$i<$nu mfields;$i++)
{
$fieldname[$i]=pg_field_name( $result,$i);
echo "<script language=\"Java script\">\n";
echo " var fieldname = new Array();\n";
foreach ($fieldname as $key => $fieldnames)
{
echo "fieldname[\"$key\"] = \"$fieldnames\" ;\n";
}
echo "</script>\n";
}

for($i=0;$i< $numrows;$i++)
{
for($j=0;$j<$nu mfields;$j++)
{
$customers[$i][$j]=pg_result($res ult,$i,$j);
echo "<script language=\"Java script\">\n";
echo "var customers = new Array();\n";
foreach ($customers as $key => $customer)
{
echo "customers[\"$key\"] = \"$customer\";\ n";
}
echo "</script<\n";
}
}
?>
[/php]

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript">
  2.     function DisplayCustomers()
  3.     {
  4.         document.write('<tr>');
  5.         for (i=0; i < numfield; i++)
  6.             {
  7.             document.write('<td>' + fieldname[i] + '</td>');
  8.             }
  9.         document.write('</tr>');
  10.     }
  11.     for (i=0; i < numrow; i++)
  12.         {
  13.         document.write('<tr>');
  14.         for (j=0; j < numfields; j++)
  15.             {
  16.             document.write('<td>' + customers[i][j] + '</td>');
  17.             }
  18.         document.write('</tr>');
  19.             }
  20.     </script>
  21.  
Apr 29 '07 #1
0 2125

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

Similar topics

16
11200
by: Craig L | last post by:
I use ASP to obtain data from a database and I have a piece of javascript code I use on my website. I want to use the database variables in my javascript. I'm not very familiar with javascript, but here is some info similar to what I'm trying to do. <% strFirstName=session("FirstName") ASP code strLastName=session("LastName") %>
2
4266
by: Craig L | last post by:
This is a solution followup to a request for help posted on 11/04/03 at 12:51pm titled "Using ASP Variables". Here is how you can make ASP variables available for use in Javascript code. I hope you find this info as valuable as I did. Thanks to everyone who helped me get to this solution with their wonderful ideas. 1) Create session objects for the variables (this example provides strings, but they could come out of a database): <!--...
8
2561
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined in global space, therefore it is not a global variable, yes? Even if it was global, how would it get from one function to another? In PHP variables are copied by value. Are they copied by reference in Javascript? <SCRIPT LANGUAGE="JavaScript">
6
11197
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I will include the code I originally used. I understand I should switch from CDONTS to CDO mail but after several sttempts I am finding a very hard time getting the new CDO mail to work properly. Any assistance with this would be greatly...
1
1301
by: Friso Wiskerke | last post by:
Hi All, We've got an VS.2003 ASPNET (VB) webproject which we would like to convert to VS.2005 so that we can make use of the Master Page feature. Converting the initial pages to 2005 is not such a problem (some minor errors) but we run into trouble when we're trying to insert a converted page into a master page content-placeholder. The original page has some Javascript in it which ofcourse references to controls in a form in the page....
4
3197
by: gg9h0st | last post by:
i'm a newbie studying php. i was into array part on tutorial and it says i'll get an array having keys that from member variable's name by converting an object to array. i guessed "i can get public members but not protected, private, static members"
9
16991
by: gwong123 | last post by:
Hey, I need to convert this javascript code into iframe. The javascript goes into a server and brings out an ad banner. The X's is the server IP. <script language="javascript" type="text/javascript" src="http://XXX.XXX.XXX.XXX/blahblah/0000/blahblahblah.php"></script> What I need to do is convert that line of code into an iframe format so that it does the same job of going into the server and pulling out the banner. Right now if I just...
17
12545
by: Shalini Bhalla | last post by:
is there any method by which i can convert javascript variables to php variables
2
2038
by: rizjabbar | last post by:
I have a js file that is being accessed through an html page. This requirement is not going to change. At this time, a need has arisen for access to the functions of these files from another program that is running in C# / .Net environmet. Is there any way to convert this file from a js file to dll. I have access to all the three codes, the only requirement is that we want to maintain one version of the js file. Here is an example of...
0
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10548
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10295
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.