SQL Query of Database into List (with JavaScript)

GeForceX

Supreme [H]ardness
Joined
Mar 19, 2003
Messages
4,172
Hi, I am hoping someone can help me out here.

I am trying to figure out how I can create a list based on the results of a SQL query, to be incorporated in JavaScript.

For example, if I have a DB table called "M" (for Months), how can I create a list based on a simple SELECT from this table, and that the list would be selectable so I can choose which month? I am trying to experiment so I can make an app for the Palm Pre (Mojo SDK).

If anyone can post a sample code or two or point me to the right area, I'd appreciate it. :)
 
Are you running the javascript on the server, or on the client? Javascript is normally run on the client. Which would mean that the SQL database system is on the client, too. Is that really how you've got things set up?
 
Hi, I am hoping someone can help me out here.

I am trying to figure out how I can create a list based on the results of a SQL query, to be incorporated in JavaScript.

For example, if I have a DB table called "M" (for Months), how can I create a list based on a simple SELECT from this table, and that the list would be selectable so I can choose which month? I am trying to experiment so I can make an app for the Palm Pre (Mojo SDK).

If anyone can post a sample code or two or point me to the right area, I'd appreciate it. :)
I'm not familiar w/ the Palm Pre or the Mojo SDK.

What I do know is that you're much better off using server side scripting (PHP, for example).

I haven't done this stuff in a while, but I'll take a stab at it:

Code:
<?php
//database variables
$user="username";
$pwd="password";
$name="myDatabase";  

//establish server connection, select a DB
$conn = mysql_connect("localhost", $user, $pwd) or die("Could Not Connect to Server");
mysql_select_db($name) or die(" Database not found.");

//query result... get April to December, assuming table has an id where 1=jan, 2=feb, etc etc
$result = mysql_query("select name from M where id > 3") or die("Bad Query");  

$num_rows = mysql_num_rows($result);
echo "<ul>";
for ( $i = 0; $i < $num_rows; $i++)
{
$row = mysql_result($result, $i);
echo "<li>$row";
}
echo "</ul>";

mysql_close();
?>

This will write an unordered list to your HTML page.

Now I think that you could feed this information into your client side javascript, or use javascript to feed this information to PHP to query the DB... but the question is why would you?
 
OP: Pending your answers to mikeblas's post, there are tons of articles on "javascript sortable grids" that can be seen from a simple Google search. Is that what you were trying to describe?
 
Now I think that you could feed this information into your client side javascript, or use javascript to feed this information to PHP to query the DB... but the question is why would you?
Assuming you're asking about why someone would get a list of months from a database, I'd agree. They're not likely to change, and are best served from a static HTML page or out of an array in an included PHP file. But perhaps GeForceX is just trying to come up with a simple example to show what he means to do without explaining the specific details; or he just wants something simple as he learns; or maybe you actually are questioning something else.
 
Just to save everyone some needless questioning, here's the quick rundown on Palm WebOS development. In short, an app is a bunch of HTML, CSS and Javascript that can "can store and retrieve data using the HTML5 database interface, or using the Cookie and Depot objects provided by the framework".

For the OP, here's a tutorial I came across when trying to make sense of the question.
 
Back
Top