I am trying this function it is possible please help me.
My code sample:
# Here is my select query
$con = mysqli_connect('localhost', 'root', '', 'test_database');
$select = "SELECT * FROM test_posts";
$select_query = mysqli_query($con, $select);
# Here is my function query
function getPosts() {
global $con;
global $select;
global $select_query;
$post = mysqli_fetch_array($select_query);
}
# Here is my homepage get posts method
while (getPosts()) {
# I am triying this method and tried define, and echo but not working
echo $post['sample_content'];
}
I am tried define('sample', '$post = mysqli_fetch_array($sample)'); but not worked.
Where is my mistake? How I should do this?
$postonly exists within the function. Return it, then define it as$post = getPosts()