1

I have a following problem: I would want to load MySQL table content dynamically, without page refresh to table using dropdown menu. I got it working with plain text with the help of this page: http://www.designing4u.de/2008/05/jquery-drop-down-loading-content-according-to-option/ but I don't know how to get content from MySQL table and print it to table instead of plain text.

For example if I have a MySQL table called "Animal" with 3 fields: Cat, Dog, Horse and a second field with information of a specific animal:

Animal ->

Cat, Dog, Horse ->

Is a cat, Is a dog, Is a horse

So I create a dropdown list: Cat, Dog, Horse and when pressing one of them, it prints information on that specific animal to HTML table.

4
  • write a php file with the required database queries. Then read about jquery ajax functions. smashingmagazine.com/2007/01/26/… Commented Apr 20, 2012 at 19:47
  • yup yup, read up on jQuery .ajax(), and if you want an easy way to deal with sql in php, look at downloading Codeigniter and then look at their Active Record Commented Apr 20, 2012 at 19:48
  • not to sound negative, but the purpose of this website isn't to solve your assignments/problems, but to help you when your stuck. At least try to do some research on your own, and if you still can't get it working, post what you've done and how it had failed. Commented Apr 20, 2012 at 19:49
  • JustCallMeNow, Yes you are right. I will put the code next time. Commented May 5, 2012 at 17:01

1 Answer 1

1

well first off im asumming that you have already connected to your database

store data in the browser to display when called

<?php
// Write out our query.
                 //colum         table          
$query = "SELECT username FROM rc_accounts WHERE isdm = '0'";
// Execute it, or return the error message if there's a problem.
$result = mysql_query($query) or die(mysql_error());
?>

display the stored data in a dropdown menu

<?php
              $dropdown = "<select name='users'>";
while($row = mysql_fetch_assoc($result)) {
  $dropdown .= "\r\n<option value='{$row['username']}'>{$row['username']}</option>";
}
$dropdown .= "\r\n</select>";
echo $dropdown; ?>

and if you what to write to it from the browser then u need this this is off of my site and its working with a check-box to confirm

<?php
if(isset($_POST['sure'])) {
mysql_query("UPDATE rc_accounts SET isdm = '1' WHERE username = '".$_POST['users']."'");
echo '<font color="#FFFF00"><b>GM Add Successfull.</font>';
} else {
echo '<font color="#FFFF00"><b>If you want to make this account a GM, then click the box!</font>';
}
?>
Sign up to request clarification or add additional context in comments.

1 Comment

I didn't got this working but I got help on this page: w3schools.com/php/php_ajax_database.asp

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.