0

I need to update a variable named $count (in the below code) automatically. When my database update, $count be update immediately because i need to use value of $count in android app so i can't refresh count.php file every time.

<?php
$con=mysql_connect("","","");
mysql_select_db("u607509006_bd1",$con);

$query = "select * from content where status='a'";
$result = mysql_query($query);
$count = mysql_num_rows($result);
echo $count;
mysql_close($con);
?>
2
  • Your can use jquery or ajax to send the data to a separate update page but that won't update the count on the current page. Commented Sep 6, 2015 at 10:08
  • Can't you just use an ajax request. The ajax request can return a value and you update your page as well. I'm not too sure about Android development, but can easily give you a solution in HTML + JS/ Jquery Commented Sep 6, 2015 at 10:12

1 Answer 1

1

Just use a Jquery Ajax Request on the client side like so:

$.ajax({
  url: "path/to/code/file.php" // change this to your path to your code
}).done(function(data) {
  // This is executed after the ajax request is complete
  // data should be the updated value. You can also return other data // types e.g. JOSN
  $('#counter').text(data);
});

JS Fiddle Example: https://jsfiddle.net/anik786/nvkdLhv2/2/

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

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.