TheDragonReborn
11-15-2008, 11:29 PM
Hello to all,
I need help populating a select field for a HTML page. What I am trying to do is retrieve data from a mySQL database and use it to fill in a select field with multiple options upon loading of a web page. My problem is with returning the data from the server to the html page. All connections are fine. Its just that nothing is being returned.
Here is my php and html/javascript code:
<?php
// Connect to database and get locus
error_reporting(E_ALL & ~E_NOTICE) ;
// Change username and password to 'ras' and '******'
$link = mysql_connect( 'localhost', 'gkoenig', '******' )
or die('Could not connect to mySQL:'.mysql_error() ) ;
// Test connection to database 'ras'
mysql_select_db('ras')
or die('Could not connect to database!') ;
// Call to Database to get list of loci
$query = "SELECT locus from rasData " ;
$result = mysql_query($query)
or die('Data retrievel failed:'.mysql_error() ) ;
// CREATE A FOR LOOP THAT TAKES ALL LOCI IN DATABASE AND PUT INTO HTML PAGE
// Get data from database and put into appropriate XML tags
while( $row = mysql_fetch_assoc($result) )
{
foreach ($row as $col)
{
echo "<option>$col</option>";
}
}
?>
function getLoci()
{
// A function to get the loci list
// change to zeus.usp.edu/~gkoenig/homework7-8/getLoci.php !!!
var url = "http://new-host.home/~Greg/homework7-8/getLoci.php" ;
xmlRequest.open("GET", url, true ) ;
xmlRequest.onreadystatechange = callBackGL ;
xmlRequest.send(null) ;
}
function callBackGL()
{
// Call back function to getLoci
if( xmlRequest.readyState == 4 )
{
//alert("Call back worked") ;
// select tag
var selectTag = document.getElementById("locusSelect") ;
if( xmlRequest.status == 200 )
{
// put info into select tag
selectTag.innerHTML = xmlRequest.responseHTML ;
//alert("Page Found") ;
}
else
{
alert("Page not Found") ;
selectTag.innerHTML = "Page Not Found!" ;
}
}
}
<body onload="getLoci();" bgcolor = "tan">
<h1 align="center">Access local RAS database</h1>
<table bgcolor="brown" align="center">
<tr>
<td>Locus:</td>
<td><select id="locusSelect" size="16" onChange="getSequenceData(this.value);"></select>
</td>
<td>
The output from the php has been tested and is what I want. I just cannot figure out how to get it to be put into my html page.
Note: I omitted code that was not relevant. Reason for breaks in code.
I used google and checked other forums with no success. Any help would be great
I need help populating a select field for a HTML page. What I am trying to do is retrieve data from a mySQL database and use it to fill in a select field with multiple options upon loading of a web page. My problem is with returning the data from the server to the html page. All connections are fine. Its just that nothing is being returned.
Here is my php and html/javascript code:
<?php
// Connect to database and get locus
error_reporting(E_ALL & ~E_NOTICE) ;
// Change username and password to 'ras' and '******'
$link = mysql_connect( 'localhost', 'gkoenig', '******' )
or die('Could not connect to mySQL:'.mysql_error() ) ;
// Test connection to database 'ras'
mysql_select_db('ras')
or die('Could not connect to database!') ;
// Call to Database to get list of loci
$query = "SELECT locus from rasData " ;
$result = mysql_query($query)
or die('Data retrievel failed:'.mysql_error() ) ;
// CREATE A FOR LOOP THAT TAKES ALL LOCI IN DATABASE AND PUT INTO HTML PAGE
// Get data from database and put into appropriate XML tags
while( $row = mysql_fetch_assoc($result) )
{
foreach ($row as $col)
{
echo "<option>$col</option>";
}
}
?>
function getLoci()
{
// A function to get the loci list
// change to zeus.usp.edu/~gkoenig/homework7-8/getLoci.php !!!
var url = "http://new-host.home/~Greg/homework7-8/getLoci.php" ;
xmlRequest.open("GET", url, true ) ;
xmlRequest.onreadystatechange = callBackGL ;
xmlRequest.send(null) ;
}
function callBackGL()
{
// Call back function to getLoci
if( xmlRequest.readyState == 4 )
{
//alert("Call back worked") ;
// select tag
var selectTag = document.getElementById("locusSelect") ;
if( xmlRequest.status == 200 )
{
// put info into select tag
selectTag.innerHTML = xmlRequest.responseHTML ;
//alert("Page Found") ;
}
else
{
alert("Page not Found") ;
selectTag.innerHTML = "Page Not Found!" ;
}
}
}
<body onload="getLoci();" bgcolor = "tan">
<h1 align="center">Access local RAS database</h1>
<table bgcolor="brown" align="center">
<tr>
<td>Locus:</td>
<td><select id="locusSelect" size="16" onChange="getSequenceData(this.value);"></select>
</td>
<td>
The output from the php has been tested and is what I want. I just cannot figure out how to get it to be put into my html page.
Note: I omitted code that was not relevant. Reason for breaks in code.
I used google and checked other forums with no success. Any help would be great