-1

I'm trying to write a web application for database managing purposes. I've written front-end of the app on HTML+CSS3 and the server-side language is PHP, but I'm still confused about how to make MySQL calls and show it to the user without refreshing/reloading the page.

Trying to be specific, here are my doubts:

  1. Can I execute a MySQL query without reloading a page?
  2. How do I show a table with query's results?
5
  • You can use Ajax in this case. Commented Nov 14, 2014 at 19:14
  • 2
    @Fred-ii- is Ajax all what you have to advice for someone who is new to HTML CSS ? Commented Nov 14, 2014 at 19:15
  • Ajax is the key: blog.teamtreehouse.com/… Commented Nov 14, 2014 at 19:16
  • 3
    @Begueradj Sorry, I left out Google. Commented Nov 14, 2014 at 19:16
  • Pretty much everything you need to take a stab at this is found here: stackoverflow.com/questions/14841057/jquery-ajax-call-of-mysql Commented Nov 14, 2014 at 19:34

1 Answer 1

3

Use Ajax for this :

Add this code to main page where you want to display table data

<html>
<head>
<script>
function dashboard() {
var query_parameter = document.getElementById("name").value;
var dataString = 'parameter=' + query_parameter;

// AJAX code to execute query and get back to same page with table content without reloading the page.
$.ajax({
type: "POST",
url: "execute_query.php",
data: dataString,
cache: false,
success: function(html) {
// alert(dataString);
document.getElementById("table_content").innerHTML=html;
}
});
return false;
}
</script>
</head>
<body>
<div id="table_content"></div>
</body>
</html>

In table_content div the data come from execute_query.php page will load without refreshing the page.

execute_query.php

$user_name = $_POST['parameter'];

$query="SELECT * from info where name=$user_name";
$result=mysql_query($query);
$rs = mysql_fetch_array($result);

do
{
?>
<table>
<tr>
<td><?php echo $rs['city']; ?></td>
<td><?php echo $rs['phone_number']; ?></td>
</tr>
</table>
<?php
}while($rs = mysql_fetch_array($result));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.