Я подсчитываю записи в базе данных и спрашиваю, больше ли это значение, чем 2. Несмотря на то, что записей нет, появляется сообщение об ошибке, которое должно быть только отображаться, если имеется более двух записей.
Код: Выделить всё
$newdate = date( 'Y-m-d', $fromform->date );
$comparedate = $DB->sql_compare_text('datum');
$comparedateplaceholder = $DB->sql_compare_text(':date');
$compareustd = $DB->sql_compare_text('ustd');
$compareustdplaceholder = $DB->sql_compare_text(':ustd');
$laptops = $DB->get_records_sql(
"SELECT COUNT(*) FROM {bs_steinweg} WHERE
{$comparedate} = {$comparedateplaceholder}
AND
{$compareustd} = {$compareustdplaceholder}",
[
'date' => $newdate,
'ustd' => $fromform->time,
]
);
var_dump($laptops);
if ( $laptops > 2 ) {
$getlaptops = get_string( 'laptopnotfree', 'local_buchungssystem' );
redirect( $CFG->wwwroot . '/local/buchungssystem/bs_sw.php', $getlaptops, null, '\core\output\notification::NOTIFY_WARNING' );
} else {
Код: Выделить всё
array(1) { [0]=> object(stdClass)#390 (1) { ["count(*)"]=> string(1) "0" } }
Где именно ошибка?
Подробнее здесь: https://stackoverflow.com/questions/786 ... -statement
Мобильная версия