I'm experiencing mysql with object-oriented php, so i created a db with only one table called users that i want to query using php classes (the insertion function properly works)
This is my php user class:
<?php
class user{
var $name;
var $surname;
var $email;
var $age;
function set_user_properties($pname, $psurname, $pemail, $page){
include "include.php";
$sql = "INSERT INTO users (name, surname, email, age)
VALUES ('$pname', '$psurname','$pemail', '$page')";
if ($conn->query($sql) === TRUE){
echo "New record created successfully";
}else{
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
function get_user_properties($name){
include "include.php";
$sql3 = "SELECT name, surname, email, age
FROM users
WHERE name='$name'";
$result3 = $conn->query($sql3);
if ($result3->num_rows > 0) {
// output data of each row
while($row3 = $result3->fetch_assoc()) {
$this->name=$row3["name"];
$this->surname=$row3["surname"];
$this->email=$row3["email"];
$this->age=$row3["age"];
}
}
$conn->close();
return $this;
}
}
?>
And this is the page where i want to read all the query results:
<?php
include("class_lib.php");
$pname=$_POST["firstname"];
$user1=new user();
$user1->get_user_properties($pname);
echo $user1->name;
echo $user1->surname;
echo $user1->email;
echo $user1->age;
?>
My question is: when i make a query which is supposed to have more than just one result (like this one), how can i pass all the results to the destination page?