Count Values with PHP and SQL

Asked

Viewed 77 times

3

Everybody, Good afternoon.

I have the following question. I have a questionnaire with 10 questions, the answers to these questions can be 0 to 5, I would like to make a while out counting the answers.

I thought the following way and concatenate as the loop was repeating.

$inicio = 1;

while($inicio <= 10){

$query = "&#36query$inicio";
$row = "&#36row$inicio";



$query = mysql_query("SELECT * FROM carrefour WHERE notapergunta1=1 AND statusPesquisa=2");
$row  = mysql_num_rows($query);





$inicio++;
}
  • did not understand your question can be more specific? what do you want to tell? if you can enter more details maybe can help.

  • So @Hardcorder, I’m going to try to be as specific as possible. I have a questionnaire in HTML and CSS with 10 questions, when people answer this questionnaire it is registered in a table the answers. I’m developing a chart for this quiz and I’m using Chartsjs to generate these graphs, the question is the following: This quiz can have grades from 0 to 5, so I’d like to create a while where I scroll through my chart to generate this automated graph, and not having to ask a query for each question.

1 answer

3

I don’t know much about PHP, but you can put with the following SQL implementations:

SELECT count(*) FROM nometabela WHERE Resposta = "1";

With this code you can echo your PHP and find out how many answers!

  • I put the code in the Pastebin so you have a notion: http://pastebin.com/aaVhQnsi

  • Managed to implement Select?

  • I got Vinicius, but I needed it to be covered in a while.

  • Can’t do it using the for?

  • André, I used a while, see on Pastebin http://www.pastebin.com/aaVhQnsi

Browser other questions tagged

You are not signed in. Login or sign up in order to post.