WebMar 9, 2024 · If you just return $statement->fetchColumn () instead, without checking > 0, you will get the exact count back instead of a boolean. Since PHP is weak/loosely typed, expressions such as 1 == true is true*, you can use the result in an if-statement too, like this WebOct 3, 2024 · It's better to use COUNT (*) instead of selecting all rows and using mysqli_num_rows (). Your basic idea was correct, you just needed to fetch the result properly. $sql = "SELECT COUNT (*) FROM news"; $count = 0; if ($result = mysqli_query ($con, $sql)) { $row = mysqli_fetch_row ($result); $count = $row [0]; } echo $count; Share
return one value from database with mysql php pdo
Webpg_fetch_all_columns() returns an array that contains all rows (records) in a particular column of the PgSql\Result instance. Note: This function sets NULL fields to the PHP … WebPDO::FETCH_BOTH (default): returns an array indexed by both column name and 0-indexed column number as returned in your result set. PDO::FETCH_BOUND: … trumps westgate
PHP mysqli fetch_field() Function - W3Schools
WebJan 12, 2016 · For fetching multiple column $query = "SELECT column1, column2,column3,column4 FROM City ORDER by ID DESC"; if ($result = mysqli_query ($link, $query)) { while ($row = mysqli_fetch_row ($result)) { printf ("%s (%s)\n", $row [0], $row [1],$row [3], $row [4]); } } Share Improve this answer Follow edited Jan 12, 2016 at … WebNov 20, 2009 · but beware of sql injection cause you are using $_GET directly in a query. The danger of injection is particularly bad because there's no database function to escape identifiers. Instead, you need to pass the field through a whitelist or (better still) use a different name externally than the column name and map the external names to column … WebTo return an array consisting of all values of a single column from the result set, specify PDO::FETCH_COLUMN. You can specify which column you want with the column parameter. To fetch only the unique values of a single column from the result set, bitwise-OR PDO::FETCH_COLUMN with PDO::FETCH_UNIQUE . trump sweden fox news