Squad Team Six Squad Team Six - 4 months ago 18
MySQL Question

Function wont echo my sql query

$Connection = mysqli_connect("localhost","username","password","host");
function getStuff($GID){
$resource= mysqli_query($Connection, "SELECT * FROM MyTable WHERE GID='$GID'");
echo mysqli_num_rows($resource);
}

getStuff(1221);


EXAMPLE: It works when I do echo mysqli_num_rows($resource); but wont work when I call that function, meaning that its nothing wrong with the $Connection or mysqli_num_rows how im calling it

Answer

try this:

function getStuff($GID){
    global $Connection;
    $resource= mysqli_query("SELECT * FROM MyTable WHERE GiD='".$GID."'", $Connection);
    echo mysqli_num_rows($resource);
}

Or this:

function getStuff($GID, $Connection){
    $resource= mysqli_query("SELECT * FROM MyTable WHERE GiD='".$GID."'", $Connection);
    echo mysqli_num_rows($resource);
}
Comments