how to check if the database is empty? my point is that the first person will be the administrator. here is my code

 $query="SELECT staffID,name,surname,email FROM stafftable";
        $do=$con->prepare($query);
        $do->execute();
        $record=$do->rowCount();
        if($record>0):

is there a much better option for this?. thanks

Looks good to me... if you have no records, and you have no limiter (where clause), you obviously have nothing in there.

You could also do "select 1 from stafftable limit 1" and it will probably be faster, but if your goal is to use the data (as yours appears to be), then the method you are using seems perfectly fine.

Well you could do something like showing some messages to know it like this:

 $query="SELECT staffID,name,surname,email FROM stafftable";
        $do=$con->prepare($query);
        $do->execute();
        $record=$do->rowCount();
        if($record>0){
            echo "Record found";
        }else{
            echo "No record found";
        }

important: it works
the code could be tighter,
BUT,
as it is there is no need for commenting, a bonus if/when a change has to be made

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.