I am new to functions so to learn about them I have been converting a website I made to use functions. I want to be able to use the function for other sites, so I am hoping to pass all the table/query information to the function, then return the posts in arrays or something similar so I can style them however needed once the function has passed the info back. I have achieved this with a single post, but can't get it to work with multiple posts. I will usually be retreiving about 10 rows, at the moment with 4 columns.
Here is my single post function
function readPostByID($postID, $table) {
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (mysqli_connect_errno()) {
return false;
}
if ($result = $mysqli->query("SELECT * FROM '$table' WHERE id = '$postID'")) {
while($row = $result->fetch_array()) {
$time1 = date('H:i \o
jS M Y', $row['publishedtime']);
$postarray['1'] = $row['title'];
$postarray['2'] = $row['content'];
$postarray['3'] = $row['author'];
$postarray['4'] = $time1;
}
$result->close();
}
mysqli_close($mysqli);
return $postarray;
}
Any help to switching this to retreive multiple posts would be appreciated
Thanks