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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display results from a database in javascript

Status
Not open for further replies.

andyfresh

Technical User
Oct 4, 2005
33
0
0
GB
Hi,

Does anyone know how to collect information from a database and then display it in an array built within javascript.

These are the three pages I have currently:

The first is the html page which will hopefully display the results.

Code:
<html>
<head>
<script src="getcontents.js"></script>
</head>
<body onload="slidemessage()">




<form name="slideshow"><div align="center"><center>
<input type="text" size="300" style="font-style: italic; border: none; background-color: transparent;">
<!--<input type="button" value="Take me there!" name="B1" onClick="window.location=messagelinks[curmsg]">--></p>
      </center></div>
    </form>


</body>
</html>

The second is the javascript which is called when the page is loaded

Code:
var curmsg=-1
var messages=new Array()
messages[0]="Message 1"
messages[1]="Message 2"
messages[2]="Message 3"

var messagelinks=new Array()
messagelinks[0]="[URL unfurl="true"]http://message1.com"[/URL]
messagelinks[1]="[URL unfurl="true"]http://www.message2.com"[/URL]
messagelinks[2]="[URL unfurl="true"]http://www.message3.com"[/URL] 

function slidemessage(){
if (curmsg<messages.length-1)
curmsg++
else
curmsg=0
//document.getelementbyname("s").value=messages[curmsg]
document.slideshow[0].value=messages[curmsg]
setTimeout("slidemessage()",4500)
}
slidemessage()

The third code is the php script which i want to use to pull the information from the database.

Code:
<? 
require_once ('../templates/mysql_connect.php');
$query = "SELECT summary, content FROM content where companyID = $company and rss = 1";
$result = @mysql_query ($query);
if ($result){	
while ($row =mysql_fetch_array($result, MYSQL_NUM)){
echo"$row[0]\n";
}
mysql_free_result ($result);
}
?>

So what I want to be able to do is instead of the message 1 message 2 and message 3 which is in the javascript code above i would like it to display the results from the database which could be an unlimited amount of results.

Can any one give me guidance on how to do this.

Regards

Andy
 
hi,

you are looking for can be done through AJAX. try a search on google, or better on this forum itself...

Known is handfull, Unknown is worldfull
 
Hi,

Ajax is always one option but as i dont know the ins and outs of it I was wondering if there was a way through javascript.

Do you think this would be the best option?
 
nope, not if databases are involved...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top