NewbieProggie NewbieProggie - 7 months ago 16
PHP Question

mysqli statement does not work under php

There's a bit problem for mysqli select statement as I did a select statement which actually counts the number of results. But it does not return the value I want but instead it returns none. Need help guys. I did this select statement as a function using mysqli and php

function count_result($data){
global $con;
$sql = "SELECT count(user_id) as userssss from credentials where user_id = '$data'";
$result = mysqli_query($con,$sql) or die('userssss');
echo "string</br>";
$row = mysqli_fetch_assoc($result,MYSQLI_ASSOC);
echo $row['userssss']."asdasd</br>";
die("userssss");
$return = $row['user'];

return $return;
}


result

string

asdasd

userssss

It should show the result before asdasd

Answer

I found it. Silly of me.

Instead of using assoc, one must use array

function count_result($data){
    global $con;
    $sql    = "SELECT count(user_id) as userssss from credentials where user_id = '$data'";
    $result = mysqli_query($con,$sql) or die('userssss');
    $row    = mysqli_fetch_array($result,MYSQLI_ASSOC);
    $return = $row['user'];

    return $return;
}