在PHP中包含并运行函数

I'm trying to put some code into an external file as a function and and run it on another page.

here is the function

function listBoats(){
    //get record set for all boats sort them by their "sort" number
    $queryBoat = "SELECT * FROM `CSINSTOCK` WHERE `id` <> 'mainPage' ORDER BY `sort` LIMIT 0, 1000";
    $result = mysqli_query($con,$queryBoat);
    return $result;

and here is how I'm including it on my page

include("monthly-specials-cs-functions.php");//get functions
listBoats(); //run query to list all the boats in the CSINSTOCK table

It doesn't seem to work. What am I doing wrong here?

Instead of include("filename.php"); you should use require_once "filename.php";

You should look into variable scope. In your case, the $con variable is undefined in the function so you would have to send it as a parameter.

all what you miss is

$con

This variable should be passed to this function or be used as a global at the beginning of function

global $con