Z
Z
zemf4you2017-05-08 18:03:56
PHP
zemf4you, 2017-05-08 18:03:56

How to count the number of certain characters in a mysql table column?

The fact is that I am a krivoruk and ignorant person.
I am writing a test in php, the essence is simple:
Only 28 people. 4 out of 28 answers are wrong, therefore, each of the 24 correct answers receives 5 points. All answers are correct - 1 point each. That is, if $q is the number of incorrect answers, then the points for this question are $q++. The most objective way to rank the difficulty of questions (the less they know the answer, the more difficult the question).
Here is a little done code (everything is there through the ass, don't hit)

<? 
include '**/bd.php'; //Данные от бд
mysql_select_db("***_bd",$connect);
$Count = 28 //Количество участников - 28

if ($CurrentCount = $Count) { //$CurrentCount - количество уже прошедших (кстати, как реализовать? По сути, надо проверить строку *человека* на наличие ответов)
for($i=a;$a<=40;$a++) { //тут это нужно (думаю, понятно, почему)
  ${q}.$a = mysql_query(SELECT * FROM answers WHERE $a = "-".) //я даже не знаю, что я написал. Нужно узнать количество минусов в столбце с номером задания
  ${answer}.$a = $q.$a + 1; //Не знаю, можно ли использовать ++, ибо вдруг 1 прибавится к номеру заданий
  echo $answer23; //Банальная проверка, не думаю, что сработает
}	
} else {
  echo <b>'Ещё не все решили тест.'<br>'Пожалуйста, подождите результатов.'</b>
}

?>

Something like that. Please explain to a newbie what and how. And then the manuals no longer help)
UPD: And also, how to create a table with 28 rows (people) and 40 columns (with the task number)? testers - people, answers - questions

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max Beetle, 2017-05-18
@zemf4you

I would make 3 tables - in the first we store users, in the second questions, in the third use_id-question_id-answer
Then to find out how many answers equal "-" to a question, you can simply: "SELECT COUNT (*) FROM `answers` WHERE question_id = 1 AND answer = '-'"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question