dewey dewey - 5 months ago 15
SQL Question

Want COUNT to return a 0 or 1 in PHP MYSQL

I have a few lines of code that's not giving me answer as I expect.

Please help me to write the best way for it:

if ("SELECT COUNT (*) FROM completed WHERE userid = $memid AND filetid = $fileid1 LIMIT 1"){
if (1) goto enz;
}


I want if
count = 1 goto enz
,
else (count is 0)
and continue with rest of program

Answer

Try in this way :

$sql = "SELECT COUNT (*) as count FROM completed WHERE userid = $memid AND filetid = $fileid1 LIMIT 1";

if ($result = mysqli_query($con,$sql)) {
    while ($row = mysqli_fetch_assoc($result)) {
        if($row['count'] == "1"){
          //Enter you code here to goto 'enz'
        } else {
          //Continue with rest of program
        }
    }
}
Comments