Jump to content

How to count results?


Darkness Soul

Recommended Posts

Yo,

I'm with a little problem.. when I do a search into my corps table, it return many lines (like, if you search for "ab" it will return 3875), and I have an IF into my select:
[code]SELECT
    tbE.id ,
    IF
    (
        palavrachave_vip LIKE "%ab%" ,
        "V" ,
        IF
        (
            tbE.cliente = "S" ,
            "S" ,
            "N"
        )
    ) AS vip
FROM
[/code]

I need to take these result and count, how much "V" and "S" I have, because they use an different css to display of each other.. and I need to count how much i'll display per time to don't broke my layout.. like it:
Page one can display:
8 result "N", or 5 result "V", or 6 result "S" or, 3 result "V" and 3 result "S"..

Do you understood? I don't know if I take the idea clear to you..

Well, is it. Thank you..

D.Soul
Link to comment
https://forums.phpfreaks.com/topic/29102-how-to-count-results/
Share on other sites

Are you looking for a summary? (no individual records) I'm not sure if V/S are mutually exclusive, but try:
[code]
SELECT
  SUM(IF(palavrachave_vip LIKE "%ab%,1,0)) AS num_v,
  SUM(IF(tbE.cliente = "S",1,0)) AS num_s,
  COUNT(tbE.id) AS num_records
FROM...
GROUP BY tbE.id
[/code]
Link to comment
https://forums.phpfreaks.com/topic/29102-how-to-count-results/#findComment-134117
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.