Below is some poorly written and heavily misunderstood PHP code with no error checking. To be honest, I\'m struggling a little getting my head around the maze of PHP->MySQLi
True, the Databasefunctions are a bit weird. You'll get there.
The code looks a bit iffy, but heres how it works:
A connection is build, a statement prepared, a parameter bound and it's executed, all well.
$result = $stmt->execute(); //execute() tries to fetch a result set. Returns true on succes, false on failure.
$stmt->store_result(); //store_result() "binds" the last given answer to the statement-object for... reasons. Now we can use it!
if ($stmt->num_rows >= "1") { //Uses the stored result and counts the rows.
while($data = $result->fetch_assoc()){
//And here, the answer-object is turned into an array-(object)
// which can be worked with nicely.
//It loops trough all entries in the array.
}
}else{
echo "0 records found";
}