Displaying the row count from mysql into a textview in android

General Tech Learning Aids/Tools 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I am trying to retrieve the row count from a mysql database and display it into a textview in android. I have the following php file:

php

error_reporting(E_ALL ^ E_DEPRECATED);

$con = mysql_connect('localhost', 'root', '');

mysql_select_db('valetdb', $con);

$result = mysql_query("select count(*) FROM drivers where datetimeparkreq is not null");

$row = mysql_fetch_array($result);

$total = $row[0];
echo "Total rows: " . $total;

?>

I was hoping to get the data from the line "$total = $row[0];". Since it does hold the count of rows. I am still learning about this whole json android php connection thing. So I would appreciate if someone will aid me! Thanks! 

profilepic.png
manpreet 2 years ago

Paolo, As the comments suggest, you should use something like the mysqli commands rather than mysql commands in php. The mysqli command to get the number of rows in a query result is mysqli_num_rows(). If you are looking to send this information to an Android app, the json format is very convenient to use. If you are sending just one piece of data, you could use php code like:

echo "{numrows:";

echo $total . "}";

On the android side you would use HttpURLConnection and related routines to send a get request to the website and JsonReader routines to parse the json object sent from the website. Hopefully this helps you get started on communicating with your website.

Mike Kagan


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.