0

I need to run an SQL query in a webpage and display the results in an HTML table. I'd like to keep this to JavaScript if possible. Just as a for instance, say I have a query:

SELECT * FROM TestTable

I want to display the results in an HTML table. Is there a way that I can dynamically draw a table that will scale to the size of the results?

Thanks!

1337Atreyu
  • 223
  • 2
  • 5
  • 12
  • 1
    What are you using on the server side? – Surya Sep 19 '14 at 18:37
  • What do you mean? The DB is a SQL Server DB if that's what you're asking. – 1337Atreyu Sep 19 '14 at 18:38
  • Where are you planning to run the query? Which will hold the query data? – Surya Sep 19 '14 at 18:39
  • The Answer is yes you can create a function to do this and account for scalability in size. But first I have a question. What are you using to call to the database and run that query? An XMLHttpRequest object? – inoabrian Sep 19 '14 at 18:40
  • Whatever works best. I figured that the query would be run in JS. I don't know if you'd also use that same function to draw the table or if you could work some HTML wizardry to accomplish that. – 1337Atreyu Sep 19 '14 at 18:41
  • Can you post the code which runs that query in JS? – Surya Sep 19 '14 at 18:42
  • Just pass the result as an array to javascript and use for-loops to create your HTML output. – newBee Sep 19 '14 at 18:43
  • I was thinking the JS code would look something like this: http://stackoverflow.com/questions/857670/how-to-connect-to-sql-server-database-from-javascript – 1337Atreyu Sep 19 '14 at 18:44
  • Care to elaborate newBee? example? – 1337Atreyu Sep 19 '14 at 18:50
  • That SO post says clearly that "You should not do it through client side" You might want to do it with Jquery's ajax call and after that it is fairly simple and easy to find help for that. – inoabrian Sep 19 '14 at 19:04

0 Answers0