Answer the question
In order to leave comments, you need to log in
How to implement this in SQL?
There is the following table structure:
There is the following code:
/ позбатомися о том, чтобы не было не было ответов с заминусованым рейтингом
$answers = $wpdb->get_results("SELECT DISTINCT `expert_id` FROM texperts_answers", ARRAY_A);
// пройдем по каждому ответу
foreach($answers as $i => $answer)
{
// получим его рейтинг
$rating = $wpdb->get_var("SELECT SUM(`rating`) FROM texperts_answers WHERE `expert_id` = " . $answer['expert_id']);
// если рейтинг меньше 0, то делаем его раным 0
if ($rating < 0) {
$wpdb->query("DELETE FROM texperts_answers WHERE `expert_id` = ". $answer['expert_id']);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question