• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Check for PDO Results, If None Display Message, If Yes then Loop Through

phppdo


PHP Snippet 1:

$results = $stm->fetchAll();
if(empty($results))//or  if(!$results)  or  if(count($results)==0)  or if($results == array())
{
    echo 'Nothing found';
}
else
{
    foreach($results as $result)
    {
        //do stuff
    }
}

PHP Snippet 2:

$stm->execute();

if($stm->rowCount() == 0)
{
    echo 'Nothing found';
}
else
{
    //do your stuff
}

Related Snippets

Too few arguments to function PendingResourceRegistration::name(),1 passed in C:xampphtdocsproject outesweb.php on line 18 and exactly 2 expected

Add custom text under order details on WooCommerce My account view order pages

Cache clear probem in Larave

Target Individual Form Instance/Counter Inside A PHP While Loop

How to make a foreign key not using primary key

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource [duplicate]

How to install php_imagick on wamp64

PHP how to detect if running on arm64 cpu?

Search for array row with specific column value and return another value from qualifying row

Python - Include another Python script

How to properly start Laravel 8 with Bootstrap & authentication

Connecting an HTML webpage to a SQL Server

PHP array stringify

How to install ZeroMQ for PHP on an Alpine Linux container?

Laravel no logout option from menu after successfull login

About Contact Privacy policy Terms and conditions