Is it possible to re-write the code below, maybe even with an if (result > 0) statement, in just one line (or simply shorter)?
// a simple query that ALWAYS gets ONE table row as result
$query = $this->db->query("SELECT id FROM mytable WHERE this = that;");
$result = $query->fetch_object();
$id = $result->id;
I’ve seen awesome, extremely reduced constructs like Ternary Operators (here and here – btw see the comments for even more reduced lines) putting 4-5 lines in one, so maybe there’s something for single result SQL queries like the above.
You could shorten
to
but this, and the original code will emit errors, if any of the functions returns an unexpected response. Better to write: