Retrieves one value from the database.
Description
Executes a SQL query and returns the value from the SQL result.
If the SQL result contains more than one column and/or more than one row, the value in the column and row specified is returned. If $query is null, the value in the specified column and row from the previous SQL result is returned.
Parameters
$query
string|nulloptional- SQL query. Defaults to null, use the result from the previous query.
Default:
null
$x
intoptional- Column of value to return. Indexed from 0. Default 0.
$y
intoptional- Row of value to return. Indexed from 0. Default 0.
Source
* @param int $x Optional. Column of value to return. Indexed from 0. Default 0.
* @param int $y Optional. Row of value to return. Indexed from 0. Default 0.
* @return string|null Database query result (as string), or null on failure.
*/
public function get_var( $query = null, $x = 0, $y = 0 ) {
$this->func_call = "\$db->get_var(\"$query\", $x, $y)";
if ( $query ) {
if ( $this->check_current_query && $this->check_safe_collation( $query ) ) {
$this->check_current_query = false;
}
$this->query( $query );
}
// Extract var out of cached results based on x,y vals.
if ( ! empty( $this->last_result[ $y ] ) ) {
$values = array_values( get_object_vars( $this->last_result[ $y ] ) );
}
Changelog
Version | Description |
---|---|
0.71 | Introduced. |
// Retrieve and display the number of users.
get total post from an user: