0

This is code taken from dynamic drive .com for Pausing up-down Scroller (text animation):

How can i take the texts from a mysql table instead of giving as an array so that i can change the content accodirngly.

var pausecontent=new Array()
pausecontent[0]='<a href="http://www.javascriptkit.com">JavaScript Kit</a><br />Comprehensive JavaScript tutorials and over 400+ free scripts!'
pausecontent[1]='<a href="http://www.codingforums.com">Coding Forums</a><br />Web coding and development forums.'
pausecontent[2]='<a href="http://www.cssdrive.com" target="_new">CSS Drive</a><br />Categorized CSS gallery and examples.'
0

2 Answers 2

0

You can convert your mysql result into a JSON object using this,

$sth = mysql_query("SELECT ...");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
 $rows[] = $r;
}
print json_encode($rows);

and this result can be accessed using ajax requests.

You will get an idea on displaying the encoded results from here JSON encode MySQL results then read using jQuery

Sign up to request clarification or add additional context in comments.

1 Comment

Hai prasanth its not working for me......it is just printing the whole mysql column content...... how to use ion java script,i tried like this..is it correct var pausecontent=json_encode();
0

what about this code?

<?php
$server_name="localhost";
    $db_user="sql_user";
    $db_pass="password";
$db="mydb";
mysql_connect($server_name, $db_user, $db_pass);
mysql_select_db($db);


$sql = "SELECT text FROM posts";
$result = mysql_query($sql) or die ('Query Error: ' . mysql_error());

while ($results = mysql_fetch_array($result))
$texts[] = $results;}

?>


<div id="map_canvas" style="width: 600px; height: 400px"></div> 

 <script type="text/javascript">

  var pausecontent = document.getElementById("<?=$texts?>");

1 Comment

what is the difference between this code and method using Json? which code is better........?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.