コード例 #1
0
 function set_to_scad_spr()
 {
     $s = '';
     //формируем начало 36 документа
     //нулевой байт
     $s .= pack('a1', '');
     $sql = "SELECT MAX(comb) FROM " . combinations;
     mysql_query($sql);
     switch (mysql_errno()) {
         case 1146:
             echo "<b>Table " . combinations . " doesn't exist. Please create DB.</b><br>";
             break;
         default:
             if (mysql_errno() > 0) {
                 echo mysql_errno() . '  ' . mysql_error() . '<br>';
             }
             $result = mysql_query($sql);
             if (mysql_num_rows($result) > 0) {
                 $comb_count = mysql_result($result, 0, 0);
                 if ($comb_count != NULL) {
                     //пишем кол-во комбинаций
                     $s .= pack('V', (string) $comb_count);
                     for ($i = 1; $i <= $comb_count; $i++) {
                         //2 нулевых байта
                         $s .= pack('a2', '');
                         $comb = new Combination();
                         $sql = "SELECT * FROM " . combinations . " WHERE comb = {$i}";
                         //                        echo $sql.'<br/>';
                         $result = mysql_query($sql);
                         if (mysql_num_rows($result) > 0) {
                             while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                                 $comb->factors[$row['koef']] = $row['value'];
                             }
                         }
                         //пишем комбинацию
                         $s .= $comb->set_to_spr();
                     }
                 } else {
                     $s .= pack('a4', '');
                 }
                 //кол-во комбинаций = 0 int 4 байта
             }
     }
     return $s;
 }