ФорумПрограммированиеPHP для идиотов → Уже не знаю че делать: Warning: Division by zero, Помогите, люди добрые

Уже не знаю че делать: Warning: Division by zero, Помогите, люди добрые

  • Tibald

    Сообщения: 1 Репутация: N Группа: Кто попало

    Spritz 20 января 2008 г. 4:00

    http://sotrudnik.org.ua - на главной странице вылетают три ошибки

    вот весь код файла, который упоминается:

    <?php
    if(USE_FEATURED_COMPANIES == "yes" && FEATURED_COMPANIES_NUMBER>0) {
    @include_once(DIR_LANGUAGES.$language."/".FILENAME_JOBFIND_FORM);
    $my_result=array();
    $tmpl_result=array();
    $body_tmpl="";
    $my_result['today']=bx_format_date(bx_mdate('Y-m-d'), DATE_FORMAT);
    $my_result['table_bgcolor']=TABLE_BGCOLOR;
    $my_result['table_featured_bgcolor']=TABLE_FEATURED_BGCOLOR;
    $my_result['text_font_face']=TEXT_FONT_FACE;
    $my_result['text_font_size']=TEXT_FONT_SIZE;
    $my_result['text_font_color']=TEXT_FONT_COLOR;
    $my_result['display_text_font_face']=DISPLAY_TEXT_FONT_FACE;
    $my_result['display_text_font_size']=DISPLAY_TEXT_FONT_SIZE;
    $my_result['display_text_font_color']=DISPLAY_TEXT_FONT_COLOR;
    $my_result['list_border_color']=LIST_BORDER_COLOR;
    $my_result['list_header_color']=LIST_HEADER_COLOR;
    $my_result['line_bgcolor']=DISPLAY_LINE_BGCOLOR_FIRST;
    $my_result['match1']=TEXT_FEATURED_COMPANIES;
    $my_result['match2']=TEXT_NO_FEATURED_COMPANY;
    $tmpl_result['html_file'][email protected](@fopen(DIR_SKIN."/featured_companies_logo_box.html","r"),@filesize(DIR_SKIN."/featured_companies_logo_box.html"));
    $ee = preg_match("/(.*)<BEGIN REPEAT>(.*)<END REPEAT>(.*)<BEGIN NORESULT>(.*)<END NORESULT>(.*)/s",$tmpl_result['html_file'], $regs);
    if (sizeof($regs)==0) {
    $tmpl_result['tmpl_header'] = $tmpl_result['html_file'];
    }
    else{
    $tmpl_result['tmpl_header'] = $regs[1];
    $tmpl_result['tmpl_main'] = $regs[2];
    $tmpl_result['tmpl_noresult'] = $regs[4];
    $tmpl_result['tmpl_footer'] = $regs[5];
    }
    if (preg_match("/^<tr/si",trim($regs[2]))) {
    $type="vertical";
    }
    else{
    $type="horizontal";
    }
    @include(DIR_BACKUP."/html/featured_companies_logo_box.html.cfg.php");
    reset($fields);
    while (list($h, $v) = each($fields)) {
    if ($my_result[$h]) {
    $tmpl_result['tmpl_header'] = str_replace($v[0],$my_result[$h],$tmpl_result['tmpl_header']);
    $tmpl_result['tmpl_footer'] = str_replace($v[0],$my_result[$h],$tmpl_result['tmpl_footer']);
    $tmpl_result['tmpl_noresult'] = str_replace($v[0],$my_result[$h],$tmpl_result['tmpl_noresult']);
    }
    else {
    $tmpl_result['tmpl_header'] = str_replace($v[0],$v[2],$tmpl_result['tmpl_header']);
    $tmpl_result['tmpl_footer'] = str_replace($v[0],$v[2],$tmpl_result['tmpl_footer']);
    $tmpl_result['tmpl_noresult'] = str_replace($v[0],$v[2],$tmpl_result['tmpl_noresult']);
    }
    }
    @include_once(DIR_BACKUP."/html/phpjob_link.cfg.php");
    reset($custom_links);
    while (list($h, $v) = each($custom_links)) {
    $tmpl_result['tmpl_header'] = str_replace($v[0],$v[2],$tmpl_result['tmpl_header']);
    $tmpl_result['tmpl_main'] = str_replace($v[0],$v[2],$tmpl_result['tmpl_main']);
    $tmpl_result['tmpl_footer'] = str_replace($v[0],$v[2],$tmpl_result['tmpl_footer']);
    $tmpl_result['tmpl_noresult'] = str_replace($v[0],$v[2],$tmpl_result['tmpl_noresult']);
    }
    $number_to_display = FEATURED_COMPANIES_NUMBER;
    $array_comps=array();
    if (FEATURED_COMPANY_ORDER==1 || FEATURED_COMPANY_ORDER==2) {
    $query = "SELECT company, compid, signupdate, logo, description, email, comp_contact, phone, fax, url, city, province, locationid FROM ".$bx_table_prefix."_companies WHERE company_suspended='0' and featured='1'";
    srand((double)microtime()*1000000); // seed the random number generator
    if (FEATURED_COMPANY_ORDER==2) {
    $array_date=array();
    $array_ordcomps=array();
    }
    }
    else {
    $query = "SELECT company, compid, signupdate, logo, description, email, comp_contact, phone, fax, url, city, province, locationid FROM ".$bx_table_prefix."_companies WHERE company_suspended='0' and featured='1' order by ".$bx_table_prefix."_companies.signupdate desc, ".$bx_table_prefix."_companies.compid desc";
    }
    $result_featured_companies=bx_db_query($query);
    SQL_CHECK(0,"SQL Error at ".__FILE__.":".(__LINE__-1));
    $count_companies=bx_db_num_rows($result_featured_companies);
    if ($count_companies!=0) {
    if ($count_companies>=$number_to_display) {
    $number_random=$number_to_display;
    }
    else {
    $number_random=$count_companies;
    }
    for($i=0;$i<$number_random;$i++) {
    $rand_row = @rand(0, ($count_companies - 1));
    $exist=random_once($array_comps,$rand_row);
    if($exist!=1) {
    $array_comps[$i]=$rand_row;
    }
    else {
    $i–;
    }
    }
    if (FEATURED_COMPANY_ORDER==1) {

    }
    elseif (FEATURED_COMPANY_ORDER==2) {
    $i=0;
    while($i<sizeof($array_comps))
    {
    $company=bx_db_data_seek($result_featured_companies, $array_comps[$i]);
    $result_companies=bx_db_fetch_array($result_featured_companies);
    $array_date[$array_comps[$i]] =$result_companies['signupdate'];
    $i++;
    }
    arsort($array_date);
    while(list($key)=each($array_date)) {
    $array_ordcomps[]=$key;
    }
    $array_comps=$array_ordcomps;
    }
    else {
    for($i=0;$i<$number_random;$i++) {
    $array_comps[$i]=$i;
    }
    }
    $i=0;
    $rows=0;
    if ($type=="vertical") {
    $n=0;
    }
    else{
    if ((FEATURED_COMPANIES_NUMBER%3==0) && (FEATURED_COMPANIES_NUMBER/3)%2!=0) {
    $n=3;
    $np=33;
    }
    else{
    $n=2;
    $np=50;
    }
    }
    while($i<sizeof($array_comps)) {
    $record=bx_db_data_seek($result_featured_companies, $array_comps[$i]);
    $result_companies=bx_db_fetch_array($result_featured_companies);
    if ($i%$n == 0 ) {
    if ($i != 0 && $type=="horizontal") {
    $body_tmpl.="</TR>";
    $body_tmpl.="<TR>\n";
    }
    }
    $rows++;
    if(floor($rows/2) == ($rows/2)) {
    $my_result['line_bgcolor']=DISPLAY_LINE_BGCOLOR_FIRST;
    }
    else {
    $my_result['line_bgcolor']=DISPLAY_LINE_BGCOLOR_SECOND;
    }
    $result_companies['signupdate'] = bx_format_date($result_companies['signupdate'], DATE_FORMAT);
    $result_companies['complink'] = HTTP_SERVER.FILENAME_VIEW."?company_id=".$result_companies['compid'];
    $result_companies['complogo'] = HTTP_SERVER."display_logo.php?company_id=".$result_companies['compid'];
    if ($result_companies['locationid']) {
    $loc_query=bx_db_query("SELECT location FROM ".$bx_table_prefix."_countries_".$bx_table_lng." WHERE ".$bx_table_prefix."_countries_".$bx_table_lng.".locationid='".$result_companies['locationid']."'");
    SQL_CHECK(0,__FILE__.":".(__LINE__-1));
    $loc_result=bx_db_fetch_array($loc_query);
    $result_companies['location']=$loc_result['location'];
    }
    $result_companies['complocation']="";
    if ($result_companies['city']) {
    $result_companies['complocation'].=$result_companies['city']." - ";
    }
    if ($result_companies['province']) {
    $result_companies['complocation'].=$result_companies['province']." - ";
    }
    $result_companies['complocation'].=$result_companies['location'];
    $temp_body_tmpl = $tmpl_result['tmpl_main'];
    reset($fields);
    while (list($h, $v) = each($fields)) {
    if ((string)$result_companies[$h]!="") {
    $temp_body_tmpl = str_replace($v[0],$result_companies[$h],$temp_body_tmpl);
    }
    elseif ((string)$my_result[$h]!="") {
    $temp_body_tmpl = str_replace($v[0],$my_result[$h],$temp_body_tmpl);
    }
    else {
    $temp_body_tmpl = str_replace($v[0],"",$temp_body_tmpl);
    }
    }
    reset($custom_links);
    while (list($h, $v) = each($custom_links)) {
    $temp_body_tmpl = str_replace($v[0],$v[2],$temp_body_tmpl);
    }
    $body_tmpl.=$temp_body_tmpl;
    if($i==$number_to_display) {
    break;
    }
    $i++;
    }
    if ($i%$n != 0) {
    while ($i%$n != 0) {
    $body_tmpl.=preg_replace("/<td([^>]+)>(.*)<\/td>/i","<td\\1>&nbsp;</td>",$temp_body_tmpl)."\n";
    $i++;
    }
    }
    }
    else{
    $body_tmpl=$tmpl_result['tmpl_noresult'];
    }
    echo $tmpl_result['tmpl_header'];
    echo $body_tmpl;
    echo $tmpl_result['tmpl_footer'];
    }
    ?>


    Это строка 134
    if ($i%$n == 0 ) {

    Это строка 187
    if ($i%$n != 0) {


    Помогите, знающие люди как исправить эту ошибку.
  • vasa_c

    Сообщения: 3127 Репутация: N Группа: в ухо

    Spritz 20 января 2008 г. 4:17, спустя 17 минут 1 секунду

    Очевидно, что для того, чтобы не возникало ошибки "деление на 0", нужно не делить на 0.
    Проверяйте, почему $n равно 0.
    При беглом просмотре заметно:

    if ($type=="vertical") {
    $n=0;
    }

Пожалуйста, авторизуйтесь, чтобы написать комментарий!