Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic SQL into Dynamic Table

Status
Not open for further replies.

pancake

Programmer
Aug 21, 2001
88
GB
I have a web page that is nearly as I want it. I have an SQL query that can select any field from a table dynamically depending upon my checkbox selections.

I know how to create a dynamic table using javascript, but can't seem to marry up how to populate the table with the SQL results. Is it possible to use some kind of parameter passing to do this ? Is there an easier way?

I have tried to think all ways around this and am at the end of my tether. Thanks for any help as my brain will soon be fried.
 
Dan,

Thanks for the input. I have the means to create my dynamic table already, it is getting the sql results into it that I am struggling with. Here is the simplified code I have so far.

The dynamic table works ok in it's own right, and the results come from the database ok. It is merging the two so the results are dynamic depending upon my field list.

Hopefully you can see my dillema.



<%@LANGUAGE="JAVASCRIPT"%>
<!--#include file="Connections/Assessment.asp" -->
<%
var Assessment = Server.CreateObject("ADODB.Recordset");
Assessment.ActiveConnection = MM_Assessment_STRING;
Assessment.Source = "SELECT * FROM assdata.txt";
Assessment.CursorType = 0;
Assessment.CursorLocation = 2;
Assessment.LockType = 1;
Assessment.Open();
var Assessment_numRows = 0;
%>
<%
var Repeat1__numRows = -1;
var Repeat1__index = 0;
Assessment_numRows += Repeat1__numRows;
%>
<html>
<head>
<title></title>



<script>
function start() {
// get the reference for the body

// split the column names
var collist="ab,cd,ef,4,5,6,7";
var colname=collist.split(",");
// This is the list of field names that are recovered from the database
var fieldlist="studname,yg,fg,4,5,6,7";
var fieldname=fieldlist.split(",");

var body = document.getElementsByTagName("body")[0];

// creates a <table> element and a <tbody> element
var tbl = document.createElement("table");
var tblBody = document.createElement("tbody");
alert(colname.length);

// headers
var row = document.createElement("tr");
for (var i = 0; i < colname.length; i++) {
// Create a <td> element and a text node, make the text
// node the contents of the <td>, and put the <td> at
// the end of the table row
var cell = document.createElement("td");
var cellText = document.createTextNode(colname);
cell.appendChild(cellText);
row.appendChild(cell);
}
tblBody.appendChild(row);
// end headers



// This section takes the array fieldlist and adds the column information depending upon this list and results
// from the database

// creating all cells
// While not end of file - put the test for eof here
for (var j = 1; j < 2; j++) {
// creates a table row
var row = document.createElement("tr");
// each cell within a row
for (var i = 0; i < fieldname.length; i++) {
// Create a <td> element and a text node, make the text
// node the contents of the <td>, and put the <td> at
// the end of the table row
var cell = document.createElement("td");

var cellText = document.createTextNode("column name goes here");
cell.appendChild(cellText);
row.appendChild(cell);
}

// add the row to the end of the table body
tblBody.appendChild(row);
}


// put the <tbody> in the <table>
tbl.appendChild(tblBody);
// appends <table> into <body>
body.appendChild(tbl);
// sets the border attribute of tbl to 2;
tbl.setAttribute("border", "2");
}
</script>
</head>


<body onLoad="start()">

</body>
</html>
<%
Assessment.Close();
%>
 
I have to ask - why don't you just write out the table using server-side code rather than client-side JS?

Given you have the data already available to you, it'd be far more efficient.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top