Difference between result() and row() in codeigniter
result() To fetch multiple records from the database table we need to use result().
row()To fetch a single record from the database table we need to use row().
Example:
result():
$query = $this->db->query("YOUR QUERY");
$data=$query->result();
foreach ($data as $row) {
echo $row['title'];
echo $row['name'];
echo $row['body'];
}
row()
result():
$query = $this->db->query("YOUR QUERY");
if ($query->num_rows() > 0) {
$row = $query->row_array();
echo $row['title'];
echo $row['name'];
echo $row['body'];
Warning: Undefined variable $article_id in
/var/www/html/st/includes/get_article.php on line
9
Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6 in /var/www/html/st/includes/get_article.php:9
Stack trace:
#0 /var/www/html/st/includes/get_article.php(9): mysqli_query()
#1 /var/www/html/st/codeigniter/result.php(123): include('...')
#2 {main}
thrown in
/var/www/html/st/includes/get_article.php on line
9