Here is my php file to retrieve users informations using recycleview
in android.
but it does not work I don't know. I need some help
Here, image is TEXT and String
, the others are varchar String
also in my database 'xxxxx' table---users
<?php
include("connect.php");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT nom, prenom, telephone, email,ncni, datenaissance, image FROM users ORDER BY id DESC ";
$result = $conn->query($sql);
if ($result->num_rows >0) {
while($row[] = $result->fetch_assoc()) {
$tem = $row;
$json = json_encode($tem);
}
} else {
echo "No Results Found.";
}
echo $json;
$conn->close();
?>
You have made a lot of mistakes in your code. You have skipped mysqli (query,fetch_assoc,num_rows should be mysqli_query,mysqli_fetch_assoc,mysqli_num_rows) everywhere. If you don't want to write mysqli multiple times, you should try PDO. Here is an example:
try {
$db = new PDO('mysql:host=localhost;dbname=DBNAME;charset=utf8',DBUSER, DBPASS);
//echo "Connected";
}
catch (PDOException $e) {
//print "Error!: " . $e->getMessage() . "<br/>";
echo "Not Connected";
die();
}
$query = $db->prepare("SELECT `nom`, `prenom`, `telephone`, `email`,`ncni`, `datenaissance`, `image` FROM `users` ORDER BY `id` DESC");
$query->execute();
if ($query->rowCount() > 0) {
$data = $query->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($data);
}
else
{
echo 'No Result Found';
}