Count numbers group wise according to identical time in PHP and MYSQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ahmurad
    New Member
    • Aug 2007
    • 19

    Count numbers group wise according to identical time in PHP and MYSQL

    Dear Xperts,

    In my database table some fault code type records are inserted and the values are like bellows:

    Error:2/FC:10; 00:15:13 16/03/2009;
    Error:2/FC:20; 00:15:15 16/03/2009;
    Error:2/FC:30; 00:15:16 16/03/2009;
    Error:2/FC:40; 00:15:20 16/03/2009;

    Error:3/FC:3; 00:20:13 16/03/2009;
    Error:3/FC:6; 00:20:15 16/03/2009;
    Error:3/FC:9; 00:20:16 16/03/2009;
    Error:3/FC:12; 00:20:25 16/03/2009;
    Error:3/FC:15; 00:20:23 16/03/2009;
    Error:3/FC:18; 00:20:26 16/03/2009;


    The database values contains in the following variables:

    $error_name[]= row[‘$db_error_name ’]; // contains all the values of 1st column
    $error_time[]= row[‘$db_error_time ’]; // contains all the values of 2nd column


    I need an SQL query/PHP statement order by same Error code(Error:2/ Error:3 )so that I can print the following output in page when it occurs at the same time (time format: hh:mm only; ex: 00:15/00:20).

    Note: Same Error code(Error:2/Error:3) types FC numbers have to count when it occurs at the same time (hh:mm dd/mm/yy).

    Output:

    4 Fault(10,20,30, 40)found // under Error:2 & time 00:15 16/03/2009;

    6 Fault(3,6,9,12, 15,18)found //under Error:3 & time 00:15 16/03/2009;


    I am waiting for your kind valued reply.

    Regards
    AHMURAD
  • ahmurad
    New Member
    • Aug 2007
    • 19

    #2
    Count numbers group wise according to identical time

    Dear Xperts,

    In my database table some fault code type records are inserted and the values are like bellows:

    Error:2/FC:10; 00:15:13 16/03/2009;
    Error:2/FC:20; 00:15:15 16/03/2009;
    Error:2/FC:30; 00:15:16 16/03/2009;
    Error:2/FC:40; 00:15:20 16/03/2009;

    Error:3/FC:3; 00:20:13 16/03/2009;
    Error:3/FC:6; 00:20:15 16/03/2009;
    Error:3/FC:9; 00:20:16 16/03/2009;
    Error:3/FC:12; 00:20:25 16/03/2009;
    Error:3/FC:15; 00:20:23 16/03/2009;
    Error:3/FC:18; 00:20:26 16/03/2009;

    The database values contains in the following variables:

    Code:
    $error_name[]= row[‘$db_error_name’]; // contains all the values of 1st column
    $error_time[]= row[‘$db_error_time’]; // contains all the values of  2nd column
    I need an SQL query/PHP statement order by same Error code(Error:2/ Error:3 )so that I can print the following output in page when it occurs at the same time (time format: hh:mm only; ex: 00:15/00:20).

    Note: Same Error code(Error:2/Error:3) types FC numbers have to count when it occurs at the same time (hh:mm dd/mm/yy).

    Output:

    4 Fault(10,20,30, 40)found // under Error:2 & time 00:15 16/03/2009;
    6 Fault(3,6,9,12, 15,18)found //under Error:3 & time 00:15 16/03/2009;


    I am waiting for your kind valued reply.

    Regards
    AHMURAD

    Comment

    • ahmurad
      New Member
      • Aug 2007
      • 19

      #3
      Mysql Query:Count numbers group wise according to identical time

      Dear Xperts,

      In my MYSQL database table some fault code type records are inserted and the values are like bellows:

      Error:2/FC:10; 00:15:13 16/03/2009;
      Error:2/FC:20; 00:15:15 16/03/2009;
      Error:2/FC:30; 00:15:16 16/03/2009;
      Error:2/FC:40; 00:15:20 16/03/2009;

      Error:3/FC:3; 00:20:13 16/03/2009;
      Error:3/FC:6; 00:20:15 16/03/2009;
      Error:3/FC:9; 00:20:16 16/03/2009;
      Error:3/FC:12; 00:20:25 16/03/2009;
      Error:3/FC:15; 00:20:23 16/03/2009;
      Error:3/FC:18; 00:20:26 16/03/2009;


      The database values contains in the following variables:

      Code:
      $error_name[]= row[‘$db_error_name’]; // contains all the values of 1st column
      $error_time[]= row[‘$db_error_time’]; // contains all the values of  2nd column
      I need an SQL query order by same Error code(Error:2/ Error:3 )so that I can print the following output in page when it occurs at the same time (time format: hh:mm only; ex: 00:15/00:20).

      Note: Same Error code(Error:2/Error:3) types FC numbers have to count when it occurs at the same time (hh:mm dd/mm/yy).

      Output:

      4 Fault(10,20,30, 40)found // under Error:2 & time 00:15 16/03/2009;

      6 Fault(3,6,9,12, 15,18)found //under Error:3 & time 00:15 16/03/2009;

      I am waiting for your kind valued reply.

      Regards
      AHMURAD

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        I have moved your posts from the jobs forum where they were automatically moderated. Please do not post there again. You posted three times because I suspect you were not able to see your other posts. You do not need to double or triple posts, if the server tells you that your post was successful then there is likely another reason that it is not visible. You are encouraged to read the FAQ under the help link at the top of the page.

        Comment

        • ahmurad
          New Member
          • Aug 2007
          • 19

          #5
          Dear Brothers,

          I have simplified the problem. Please see the Present and Expected Output Status. Please give me a solution modifying the PHP/MYSQL code. I am not so familiar with group by, order by, having clauses.

          DB Table:

          Error_Code FC_No FC_Time

          Error:2 FC:10 00:15:13
          Error:2 FC:20 00:15:15
          Error:2 FC:30 00:15:16
          Error:2 FC:40 00:15:20
          Error:3 FC:3 00:20:13
          Error:3 FC:6 00:20:15
          Error:3 FC:9 00:20:16
          Error:3 FC:12 00:20:20
          Error:3 FC:15 00:20:16
          Error:3 FC:18 00:20:20

          [CODE=PHP]

          $view= mysql_query("SE LECT * FROM db_table WHERE Occurrence_Date = '".$fdate."' ");

          while( $searchresult = mysql_fetch_arr ay($view) )
          {
          $error_code = $searchresult[‘db_error_ code’]; //contains all the values of Error_Code
          $error_no = $searchresult[‘db_error_ no’]; //contains all the values of FC_No
          $error_time = $searchresult[‘db_error_ time’]; //contains all the values of FC_Time
          Print “1 Fault($error_no )found”;
          }

          [/CODE=PHP]

          Hints: Same Error_Code(Erro r:2/Error:3) types FC_No have to count when it occurs at the same time (hh:mm).

          Present Output :

          //Under Error:2
          1 Fault(10)found
          1 Fault(20)found
          1 Fault(30)found
          1 Fault(40)found

          //Under Error:3
          1 Fault(3)found
          1 Fault(6)found
          1 Fault(9)found
          1 Fault(12)found
          1 Fault(15)found
          1 Fault(18)found

          Expected output:

          4 Fault(10,20,30, 40)found // under Error:2 & time 00:15
          6 Fault(3,6,9,12, 15,18)found //under Error:3 & time 00:20

          Comment

          Working...