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. :)
 

mikeblas

[H]ard|DCer of the Month - May 2006
Joined
Jun 26, 2004
Messages
12,776
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?
 

noobman

[H]ard|Gawd
Joined
Oct 15, 2005
Messages
1,475
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?
 

PTNL

Supreme [H]ardness
Joined
Jan 2, 2005
Messages
4,196
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?
 

mikeblas

[H]ard|DCer of the Month - May 2006
Joined
Jun 26, 2004
Messages
12,776
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.
 

ameoba

Supreme [H]ardness
Joined
Jan 9, 2001
Messages
6,413
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.
 
Top