From f82e5456d22af7e39a22a9a64e74072cf01e0a31 Mon Sep 17 00:00:00 2001 From: msquare Date: Fri, 28 Jul 2017 20:11:09 +0200 Subject: dried code by introducing selectOne for select queries with only one result line expected --- includes/pages/admin_questions.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'includes/pages/admin_questions.php') diff --git a/includes/pages/admin_questions.php b/includes/pages/admin_questions.php index d05bace6..2b61b055 100644 --- a/includes/pages/admin_questions.php +++ b/includes/pages/admin_questions.php @@ -105,11 +105,11 @@ function admin_questions() return error('Incomplete call, missing Question ID.', true); } - $question = DB::select( + $question = DB::selectOne( 'SELECT * FROM `Questions` WHERE `QID`=? LIMIT 1', [$question_id] ); - if (count($question) > 0 && $question[0]['AID'] == null) { + if (!empty($question) && $question['AID'] == null) { $answer = trim( preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', @@ -129,7 +129,7 @@ function admin_questions() $question_id, ] ); - engelsystem_log('Question ' . $question[0]['Question'] . ' answered: ' . $answer); + engelsystem_log('Question ' . $question['Question'] . ' answered: ' . $answer); redirect(page_link_to('admin_questions')); } else { return error('Enter an answer!', true); @@ -145,13 +145,13 @@ function admin_questions() return error('Incomplete call, missing Question ID.', true); } - $question = DB::select( + $question = DB::selectOne( 'SELECT * FROM `Questions` WHERE `QID`=? LIMIT 1', [$question_id] ); - if (count($question) > 0) { + if (!empty($question)) { DB::delete('DELETE FROM `Questions` WHERE `QID`=? LIMIT 1', [$question_id]); - engelsystem_log('Question deleted: ' . $question[0]['Question']); + engelsystem_log('Question deleted: ' . $question['Question']); redirect(page_link_to('admin_questions')); } else { return error('No question found.', true); -- cgit v1.2.3-54-g00ecf