Search code examples
phpdatabasedrupaldrupal-7

how i can select only the type of the variables in the drupal watchdog database table?


*****~PLZ HELP~***I want to spesialize the variables and take the type e.g 'Notice', 'Error'..In this code that follows execute something like this

3710 a:6:{s:5:"%type";s:6:"Notice";s:8:"!message";s:24:"Undefined variable: path";s:9:"%function";s:3:"l()";s:5:"%file";s:44:"c";s:5:"%line";i:2469;s:14:"severity_level";i:5;}

3711 a:6:{s:5:"%type";s:6:"Notice";s:8:"!message";s:24:"Undefined variable: path";s:9:"%function";s:3:"l()";s:5:"%file";s:44:"/c";s:5:"%line";i:2511;s:14:"severity_level";i:5;}

3712 a:6:{s:5:"%type";s:7:"Warning";s:8:"!message";s:141:"Missing argument 2 for l(), called in on line 171 and defined";s:9:"%function";s:3:"l()";s:5:"%file";s:44:"";s:5:"%line";i:2458;s:14:"severity_level";i:4;}

3713 a:6:{s:5:"%type";s:6:"Notice";s:8:"!message";s:24:"Undefined variable: path";s:9:"%function";s:3:"l()";s:5:"%file";s:44:"";s:5:"%line";i:2469;s:14:"severity_level";i:5;}**

    function blabla_page() {

          // Begin building

 the query.
      $query = db_select('watchdog', 'th')
        ->extend('PagerDefault')
        ->orderBy('wid')
        ->fields('th')
        ->limit(10);

    // Fetch the result set.
    $result = $query->execute();

      // Loop through each item and add to the $rows array.
      foreach ($result as $row) {
        $rows[] = array(
        $row -> wid,
        $row -> variables,
       );
      }
    // Headers for theme_table().
      $header = array('ID', 'Message');

    // Format output.
      $output = theme('table', array('header' => $header, 'rows' => $rows)). theme('pager');
         return $output;
       }

Solution

  • The information in the field is serialized this should do it.

      foreach ($result as $row) {
        $message1=unserialize($row->variables);
        if($message1['%type']){
          $rows[] = array(
          $row -> wid,
          $message1['%type'],
        );
       }
      }
    

    Now the output will only be added to the rows array when the %type item exists