473,466 Members | 3,167 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Convert raw data to well formed rows

hsriat
1,654 Recognized Expert Top Contributor
I have to make a data grid, in which data is shown directly from database.
I have done it by using PHP scripting with a while loop. ie. It would keep on fetching arrays from database and generate corresponding row one by one.
But with few rows its fine. As the number of rows and size of each row will increase, it will end up making it a huge HTML.

So I was thinking of using javascript to add rows. So I made a function to which I passed the row fields as arguments and it generates corrosponding row for the table.

The function is working fine if i call it manually by typing it in the address bar, but it is not adding rows when I call it on body's onload...
Where should I call that function?
Expand|Select|Wrap|Line Numbers
  1. function insRs() {
  2. insR('a1','a2','a3','a4','a5','a6','a7');
  3. insR('b1','b2','b3','b4','b5','b6','b7');
  4. insR('c1','c2','c3','c4','c5','c6','c7');
  5. insR('d1','d2','d3','d4','d5','d6','d7');
  6. }
Feb 20 '08 #1
16 1839
hsriat
1,654 Recognized Expert Top Contributor
I solved the problem.
Feb 20 '08 #2
acoder
16,027 Recognized Expert Moderator MVP
Post your solution in case someone has a similar problem.
Feb 20 '08 #3
hsriat
1,654 Recognized Expert Top Contributor
Post your solution in case someone has a similar problem.
Just leave the table blank where you need to display the data.
In PHP code...
[php]<?php
echo "
<body onload=\"insAllRws();\">
<table class=\"grid\" id=\"table\"></table>
<script type=\"text/javascript\">
function insAllRws() {";
while($rw = mysql_fetch_array($sql))
echo "
insR('".$rw[a]."','".$rw[b]."','".$rw[c]."','".$rw[d]."','".$rw[e]."')";
echo "
}
</script>
</body>";
?>[/php]

Make a function to add rows...
Expand|Select|Wrap|Line Numbers
  1. function insR(a,b,c,d,e) {
  2.   var txt = new Array(a,b,c,d,e);
  3.   var tbl = document.getElementById('table');
  4.   var num = tbl.rows.length;
  5.   var rw = table.insertRow(num);
  6.   var flds = new Array;
  7.   for (var i=0; i<5; i++) { //for fields
  8.     flds[i] = rw.insertCell(i);
  9.     flds[i].innerHTML = txt[i];
  10.   }
  11. }
  12.  
Earlier my HTML file was 78 KB along with a JS file of 14 KB
Now, HTML is 12 KB and JS is still 14 KB
Feb 20 '08 #4
acoder
16,027 Recognized Expert Moderator MVP
Just leave the table blank where you need to display the data.
...Make a function to add rows...
You could put insAllRs in the head. Anyway, thanks for posting your solution.
Feb 20 '08 #5
hsriat
1,654 Recognized Expert Top Contributor
You could put insAllRs in the head. Anyway, thanks for posting your solution.
Yeh it was working fine in the head.
But I display Loading... in the center of the page while the page is loading.
And its algo is in such a way that if I'll keep insAllRs() in head, it loads the function insAllRs() before displaying Loading....Since all the data is inside the insAllRs() function, it takes time to load. And if I'll keep it inside the body, the Loading.. thing is displayed before loading the insAllRs() function. So I prefered using it inside the body.
I don't think any browser will effect its working.
If it would, then we'll see it later. ;)
Feb 20 '08 #6
hsriat
1,654 Recognized Expert Top Contributor
You could put insAllRs in the head. Anyway, thanks for posting your solution.
Is it harmful to put it inside the body in any case?
Feb 21 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
Yeh it was working fine in the head.
But I display Loading... in the center of the page while the page is loading.
And its algo is in such a way that if I'll keep insAllRs() in head, it loads the function insAllRs() before displaying Loading....Since all the data is inside the insAllRs() function, it takes time to load. And if I'll keep it inside the body, the Loading.. thing is displayed before loading the insAllRs() function. So I prefered using it inside the body.
Since insAllRws is called on body onload, it shouldn't affect it. How do you display the loading message?
Feb 21 '08 #8
acoder
16,027 Recognized Expert Moderator MVP
Is it harmful to put it inside the body in any case?
I wouldn't say harmful, but it's cleaner to have it in the head, if possible. Even better would be to have no JavaScript in the page and just link to it (keep it unobtrusive).
Feb 21 '08 #9
hsriat
1,654 Recognized Expert Top Contributor
I wouldn't say harmful, but it's cleaner to have it in the head, if possible. Even better would be to have no JavaScript in the page and just link to it (keep it unobtrusive).
Yeah I always keep javascript in different file, but this time its generated by the PHP code and each time the function would contain different arguments. So I kept it in.

Thanks for your response!... :)

And tell me about this .
Feb 21 '08 #10
acoder
16,027 Recognized Expert Moderator MVP
Yeah I always keep javascript in different file, but this time its generated by the PHP code and each time the function would contain different arguments. So I kept it in.
If the PHP code is generating JavaScript, link to the PHP file.
Feb 21 '08 #11
hsriat
1,654 Recognized Expert Top Contributor
Since insAllRws is called on body onload, it shouldn't affect it. How do you display the loading message?
The first line of the body says Loading.... And the whole other part is in a div with style="display:none;".
As soon as the page loads it first displays loading.. while the other part is loading.
In the onload event of body, after all other function(which are needed to be called), toggle style.display for loading-div and the remaining-page-div.

If I keep the function in head, the loading.. will be displayed after loading the function, but now it displays before loading the function.
Feb 21 '08 #12
hsriat
1,654 Recognized Expert Top Contributor
If the PHP code is generating JavaScript, link to the PHP file.
I didn't get it.... :(
Feb 21 '08 #13
acoder
16,027 Recognized Expert Moderator MVP
The first line of the body says Loading.... And the whole other part is in a div with style="display:none;".
As soon as the page loads it first displays loading.. while the other part is loading.
In the onload event of body, after all other function(which are needed to be called), toggle style.display for loading-div and the remaining-page-div.

If I keep the function in head, the loading.. will be displayed after loading the function, but now it displays before loading the function.
Does the function take a long time to be loaded?
Feb 21 '08 #14
acoder
16,027 Recognized Expert Moderator MVP
I didn't get it.... :(
Say, the PHP file is called js.php. It's a PHP file, but it generates JavaScript code, so you could link to it, e.g.
[HTML]<script type="text/javascript" src="js.php"></script>[/HTML]
Feb 21 '08 #15
hsriat
1,654 Recognized Expert Top Contributor
Does the function take a long time to be loaded?
yeah, it does.

Look at the first post. Its actually fetching all the rows from database.
Rows may be more than 100, and each may have good data. So it may take time.


Thanks for js.php... I got it.
Feb 21 '08 #16
acoder
16,027 Recognized Expert Moderator MVP
yeah, it does.

Look at the first post. Its actually fetching all the rows from database.
Rows may be more than 100, and each may have good data. So it may take time.
Well, in that case, I guess it'll have to stay in the body.
Feb 21 '08 #17

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

Similar topics

22
by: googlegroups | last post by:
I am playing with the XMLHTTPRequest method to perform client/server transactions. I have it set up right now so that when readyState is 4, it takes the XML and processes it. This works great until...
3
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
4
by: 2003et | last post by:
Hi, I have a search system which shows results in REPEATER but, it shows, for example 80 data item once, but I want to show the results page by page in groups of 10. 1-10 11-20 21-30 ... etc....
19
by: jcrouse | last post by:
I decided to start a new thread. I have output in xml file format. It looks like this: <P1JoyUp> <Top>326</Top> <Left>54</Left> <Height>23</Height> <Width>100</Width> <Visible>True</Visible>...
9
by: MR | last post by:
I get the following Exception "The data at the root level is invalid. Line 1, position 642" whenever I try to deserialize an incoming SOAP message. The incoming message is formed well and its...
5
by: manmit.walia | last post by:
Hello All, I am stuck on a conversion problem. I am trying to convert my application which is written in VB.NET to C# because the project I am working on currently is being written in C#. I tried...
1
by: DSmith1974 | last post by:
Hi All, Can anyone help with the following problem? I have a database which contains a table with a 'text' field, and the text field contains an xml document - typically 50-100K. Now I'd like...
3
by: Hari | last post by:
Hi all, I have written a web service that receives large volume of data from consumers and process this data. When a consumer is sending large data (say xml files of 50KB) at frequent...
5
by: bbb | last post by:
Hi, I need to convert XML files from Japanese encoding to UTF-8. I was using the following code: using ( FileStream fs = File.OpenRead(fromFile) ) { int fileSize = (int)fs.Length; int buffer...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.