• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

jQuery and SQL to pull and place random text from database

How would one use jQuery to randomly select a column from a table in an SQL database that would then be shown to the user on a page?
0
Michael Sterling
Asked:
Michael Sterling
  • 2
  • 2
2 Solutions
 
Michael SterlingWeb Applications DeveloperAuthor Commented:
this needs to occur when the page loads. and only needs to do the random select once, not on a timer...
0
 
leakim971PluritechnicianCommented:
if you do it only one time, at page load you should be able to do that on the server side directly.

else of course your answer is ajax : http://api.jquery.com/jQuery.get/

you need to create an .net page returning the random column
<script>
$(document).ready(function() {
    $.get( "page.aspx/randomColum", null, function(data) { $("#here").html(data); } );
});
</script>
<body>
<div id="here"></div>

Open in new window

0
 
Mike DSolution ConsultantCommented:
...and with serverside he means something like

<?

echo "<script>";
echo "var =" . $my_rand_nr;
echo "</script>";

?>

Greets
JD
0
 
Michael SterlingWeb Applications DeveloperAuthor Commented:
thank you.
0
 
leakim971PluritechnicianCommented:
You're welcome! Thanks for the points!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now