473,320 Members | 1,854 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,320 software developers and data experts.

dynamically displaying all the contents of table

I had made a table in a pgsql database which has 4 columns and 4 rows. now I want to display the data of the table in textfields . My table is like this

userid username fname lname
123 anuragpj anurag johari
223 anu anu verma
254 qewdh dqkjh jdnaj
444 hari dfjhj jhdasnb

I m using this php script to store the data in variable.

[PHP]<?
// make our connection
$connection = pg_connect("host=localhost dbname=mydb user=postgres");

// let me know if the connection fails
if (!$connection) {
print("Connection Failed.");
exit;
}

// declare my query and execute
$myresult = pg_exec($connection, "SELECT * FROM users where id>100");

// process results
for ($lt = 0; $lt < pg_numrows($myresult); $lt++) {
$id = pg_result($myresult, $lt, 0);
$username = pg_result($myresult, $lt, 1);
$fname = pg_result($myresult, $lt, 2);
$lname = pg_result($myresult, $lt, 3);
}
?>[/PHP]

can I generate the number of textfields needed automatically? If yes then how can i do this?
Jan 25 '07 #1
7 2499
ronverdonk
4,258 Expert 4TB
Although I have no PostgreSQL to test, I will show you a reworked version of my MySQL snippet. It calculates the no of fields and starts an output table with each field name in the heading. It then processes all result rows. For each row it displays the values of each field in an output table row.

As I said, I have no pg available, so there could be a typo or error in there. Good luck.[php]// get no of fields
$numflds = pg_num_fields($res);
// start the output table
echo "<table><tr>";
// generate table headings
for ($j = 0; $j < $numflds; $j++) {
$fieldname = pg_field_name($res, $j);
echo '<th>'.$fieldname.'</th>';
}
echo "</tr>";
// process each result row
for ($lt = 0; $lt < pg_numrows($myresult); $lt++) {
// process each result field within a row
echo '<tr>';
for ($i=0; $i<$numflds; $i++)
echo '<td>'.pg_result($myresult, $lt, $i).'</td>';
echo '</tr>';
}
echo "</table>";[/php]
Ronald :cool:
Jan 25 '07 #2
Although I have no PostgreSQL to test, I will show you a reworked version of my MySQL snippet. It calculates the no of fields and starts an output table with each field name in the heading. It then processes all result rows. For each row it displays the values of each field in an output table row.

As I said, I have no pg available, so there could be a typo or error in there. Good luck.[php]// get no of fields
$numflds = pg_num_fields($res);
// start the output table
echo "<table><tr>";
// generate table headings
for ($j = 0; $j < $numflds; $j++) {
$fieldname = pg_field_name($res, $j);
echo '<th>'.$fieldname.'</th>';
}
echo "</tr>";
// process each result row
for ($lt = 0; $lt < pg_numrows($myresult); $lt++) {
// process each result field within a row
echo '<tr>';
for ($i=0; $i<$numflds; $i++)
echo '<td>'.pg_result($myresult, $lt, $i).'</td>';
echo '</tr>';
}
echo "</table>";[/php]
Ronald :cool:
if it will work it will display the information in a table but I want that information to be displayed in a textfield so that I can edit and update it.

If u can help it then please reply soon.
Jan 26 '07 #3
ronverdonk
4,258 Expert 4TB
if it will work it will display the information in a table but I want that information to be displayed in a textfield so that I can edit and update it.

If u can help it then please reply soon.
Then make each table cell an input field by using the <input name=..... /> in that cell.

Ronald :cool:
Jan 26 '07 #4
Then make each table cell an input field by using the <input name=..... /> in that cell.

Ronald :cool:
can u explain it with an example. Please
Jan 27 '07 #5
ronverdonk
4,258 Expert 4TB
Now this question goes far beyond your original post. That was about dynamically displaying columns of a result set for a PostGreSQL table.

What you are asking now is something completely different, i.e. now you want to turn this display into a full fledged grid with edit and save options. From the ground up!
That goes beyond the scope of this thread and even this forum. Not mentioning the huge amount of new lines of code developed.

I will show you the basic functions you have to think of.
- enclose the shown table in a form
- make each cell in the table an input field with its own unique name (or ID if you are using JS)
- let the user submit the form when completed
- write the code to capture all changed fields in the form after submit
- update each row in the table with the changed fields

But I must warn you that this is not a simple task, updateable grids are relatively difficult.

A better solution for you would be to look into the use of an administration tool for PostGreSQL. Those tools usually have grid capabilities.

Ronald :cool:
Jan 28 '07 #6
cassbiz
202 100+
This almost sounds like a case where you would want to use AJAX. If you do display it in a text fields, then when the field is changed it will update automatically. Otherwise you may be attempting to re-invent the wheel.

Good Luck
Jan 29 '07 #7
Now this question goes far beyond your original post. That was about dynamically displaying columns of a result set for a PostGreSQL table.

What you are asking now is something completely different, i.e. now you want to turn this display into a full fledged grid with edit and save options. From the ground up!
That goes beyond the scope of this thread and even this forum. Not mentioning the huge amount of new lines of code developed.

I will show you the basic functions you have to think of.
- enclose the shown table in a form
- make each cell in the table an input field with its own unique name (or ID if you are using JS)
- let the user submit the form when completed
- write the code to capture all changed fields in the form after submit
- update each row in the table with the changed fields

But I must warn you that this is not a simple task, updateable grids are relatively difficult.

A better solution for you would be to look into the use of an administration tool for PostGreSQL. Those tools usually have grid capabilities.

Ronald :cool:
I m asking that how to make each table cell an input field. please give a small example related this.
Jan 29 '07 #8

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

Similar topics

3
by: Andrew Dodgshun | last post by:
I have 2 grids - one shows a list of table names in a database and when you click on a table name the other grid dynamically populates the grid with the table contents. My problem is that I cannot...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
1
by: npaulus | last post by:
Hi, I am trying to dynamically add user controls on to my web form but for some reason my form isnt displaying the user control. form1.cs: using System; using System.Drawing; using...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
16
by: listerofsmeg01 | last post by:
Hi all, New to Javascript, and want to learn to do things the RIGHT way. I have a dynamic table which is populated using Javascript. Currently I am looking at adding nodes using the W3C DOM,...
3
by: StevenT | last post by:
Hello, I am trying to dynamically create a table based on the information I have in my cookie for a shopping cart. I can create it and display it and all is good. I put the contents of the...
29
by: shivasusan | last post by:
Hi! I can add rows with inputs to my HTML table dynamically using DOM, but I cannot remove selected rows. In fact, every row contains a Delete button. So, user selects the rows to remove, clicks...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.