I have the following table in phpmyadmin.
The name of the table is data:
Im trying to use php file in order to obtain all of the rows where the user_id for example equals to 3 using prepared statements as follows:
<?php
session_start();
$DATABASE_HOST = "localhost";
$DATABASE_USER = "root";
$DATABASE_PASS = "XXX";
$DATABASE_NAME = "XXX";
$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if ($stmt = $con->prepare('SELECT code FROM data WHERE user_id = ?')) {
$stmt->bind_param('s', $_POST['user_id']);
$stmt->execute();
$stmt->bind_result($col1);
while ($row = $stmt->fetch()) {
echo $col1;
}
$stmt->close();
}
$con->close();
?>
This code works and returns one long string that consists of all the codes.
My goal eventually is to obtain some array into java where each cell inside the array will have one code.
What is the best way to obtain from php an array that I will be able to use in java?
Thank you