0

I need to make a call from my webpage to database and select random picture from single table from database. Database is based on server (mysql) and i call it from javascript code. So my question is: Is there a code snippet for that, I am not that good with Javascript.

Thanks in advance.

3
  • 2
    Javascript can't connect directly to mySQL. What are you using on server side? Commented Nov 26, 2010 at 18:14
  • 1
    You left out the server-side language you're using. That's what you need to write an API in. Also, you might want to show your db schema. Commented Nov 26, 2010 at 18:14
  • i am using php as a server side language Commented Nov 26, 2010 at 19:33

2 Answers 2

1

You can do this in your Server-Side Script. Eg: PHP , ASP.Net

Look this: Random images shower

Maybe it isn't related to question but you should stroe your pics link in database. You should try to store pics in your web-site directory , for example

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

2 Comments

Where do i need to put server-side script, in witch directory?
I think you should use AJAX. Here is a good example: w3schools.com/PHP/php_ajax_database.asp
1

You need a server side script that gives you the picture. Then you need some js that loads it. If you use php, and jQuery on the client-side, your js could look like:

$('div#image_container').load('yourscript.php');

And then your php would query the database and return something like:

<img src="the_random_image_url.jpg" />

Comments

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.