This is how I get the field comment
from the table kh_comments
.
public function get_the_comment($internal_page_id) {
$conn = new mysqli($this->servername, $this->username, $this->password, $this->db_name);
if (!empty($internal_page_id)) {
$stmt = $conn->prepare("SELECT comment FROM kh_comments WHERE page_id = ?");
$stmt->bind_param('s', $internal_page_id);
}
$stmt->execute();
$stmt->bind_result($comment);
while ($stmt->fetch()) {
return $comment;
}
$stmt->close();
$conn->close();
}
Now let's say we have an array on the second parameter like this
public function get_the_comment($internal_page_id, $array) {
and $array
would look like this:
array(3) {
[0]=>
string(4) "name"
[1]=>
string(3) "age"
[2]=>
string(8) "location"
}
How would it be possible to use the values of the array for getting values from a MySQL table which has the same column names?
The result would be somehow like this:
$stmt = $conn->prepare("SELECT comment FROM name, age, location WHERE page_id = ?");
...