jQuery and SQL to pull and place random text from database

Posted on 2010-09-02
Medium Priority
Last Modified: 2012-05-10
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?
Question by:Michael Sterling
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Author Comment

by:Michael Sterling
ID: 33591420
this needs to occur when the page loads. and only needs to do the random select once, not on a timer...
LVL 82

Accepted Solution

leakim971 earned 1000 total points
ID: 33592124
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
$(document).ready(function() {
    $.get( "page.aspx/randomColum", null, function(data) { $("#here").html(data); } );
<div id="here"></div>

Open in new window


Assisted Solution

by:Mike D
Mike D earned 1000 total points
ID: 33676516
...and with serverside he means something like


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



Author Closing Comment

by:Michael Sterling
ID: 33801366
thank you.
LVL 82

Expert Comment

ID: 33801392
You're welcome! Thanks for the points!

Featured Post

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question