I have this PHP code that selects one simple value:
$name = $mysqli->query('SELECT name FROM users WHERE id = ' . $id . ' LIMIT 1')->fetch_object()->name;
Now if the result is 0, it throws an error.
I want instead to return a default value like "No name" if there are no results.
Any suggestions?
if ($result == null) return 'No Name'
; before youfetch_object()
SELECT IFNULL(name, 'no name') FROM...
if/else
.