在代码中除以零

时间:2011-12-26 07:00:03

标签: php wordpress

我一直在研究site。它显示以下错误,

  

警告:除以零   /home/sunshine/public_html/wp-content/themes/DailyDeal/index.php on   第63行

现在我去检查index.php文件,但是在第63行我只有一个右大括号(}

如果有人能在这里指出错误(我已经尝试停用所有插件但问题仍然存在),我将非常感激。 以下是参考文献

的完整index.php
<?php get_header(); ?>

<script type="text/javascript" >

var root_path_js = '<?php echo get_option('siteurl')."/";?>';

</script>

<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/library/js/jquery-ui-1.8.14.custom.min.js"></script>

<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/timer.js"></script>

<script type="text/javascript">

jQuery.noConflict();

    function a()

    {

        return false;

    }

    jQuery(function() { 

        jQuery( "#slider-range-min-var" ).slider({

            range: "min",

            value: jQuery("#sellsqlinfo1").val(),

            min:  0,

            max: jQuery("#noofcoupon1").val(),

            enable: false,

            slide: function( event, ui ) {

                jQuery("#amount").val("$"+ ui.value );

            }

        });

        jQuery( "#amount" ).val( "$" + jQuery( "#slider-range-min-var" ).slider( "value" ) );



    });

</script>

<?php

/* Mail To Friend BOF */

if($_POST['sendact']=='email_frnd') {

    require_once (TEMPLATEPATH . '/monetize/send_to_friend/email_friend_frm.php');exit;

}

/* Mail To Friend EOF */

/* Home Page Deal Display BOF */

global $wpdb,$deal_db_table_name;   

$postmeta_db_table_name = $wpdb->prefix."postmeta";

$post_db_table_name = $wpdb->prefix."posts";

$destination_path = site_url().'/wp-content/uploads/';

$args = array('numberposts' => 1,'meta_key' =>'is_expired' , 'meta_value' =>'0','post_status' => 'publish','post_type' => 'seller','meta_key' =>'status' , 'meta_value' =>'2' ,'orderby' => 'DESC');

$recent_posts = get_posts( $args );

if(mysql_affected_rows() > 0) { // 1st IF Condition BOF

    $post_large = bdw_get_images($destination_path.get_post_meta($post->ID,'file_name',true),'large');

    $post_images = bdw_get_images($destination_path.get_post_meta($post->ID,'file_name',true),'thumb'); ?>

    <div class="top_content">

<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('home_above')) { } else {  }?>

    </div>

<!-- top content #end -->

    <div class="box_header"></div>

    <div class="box_bg">

    <div class=" box_bottom">

<?php foreach( $recent_posts as $post ){  // foreach loop BOF

        if((get_post_meta($post->ID,'status',true) == 2) && (get_post_meta($post->ID,'is_expired',true) == 0)) { 

            deal_expire_process($post->ID); 

            $home_deal_id = $post->ID;

            global $home_deal_id;

            $coupon_website= get_post_meta($post->ID,'coupon_website',true);

            $owner_name= get_post_meta($post->ID,'owner_name',true);

            $our_price= get_post_meta($post->ID,'our_price',true);

            $current_price= get_post_meta($post->ID,'current_price',true);

            $sellsql = "select count(*) from $transection_db_table_name where post_id=".$post->ID." and status=1";

            $totdiff = $current_price - $our_price;

            $percent = $totdiff * 100;

            $percentsave = $percent/$current_price;

            $sellsqlinfo = $wpdb->get_var($sellsql);

            $date = get_post_meta($post->ID,'coupon_end_date_time',true);

            $tardate= date("F d, Y H:i:s",get_post_meta($post->ID,'coupon_end_date_time',true));

            $stdate= date("F d, Y H:i:s",get_post_meta($post->ID,'coupon_start_date_time',true));

            $tardate1= date("F d, Y",get_post_meta($post->ID,'coupon_end_date_time',true));

            if(get_post_meta($post->ID,'coupon_end_date_time',true) != "") {

                if(date("Y-m-d H:i:s") >= $tardate1 && get_post_meta($post->ID,'enddate',true) != '0' || (get_post_meta($post->ID,'no_of_coupon',true)==$sellsqlinfo)) {

                    if(get_post_meta($post->ID,'is_expired',true)== '0' || get_post_meta($post->ID,'is_expired',true)== '') {

                        update_post_meta($post->ID,'is_expired','1');

                    }

                }

            } else {

                if(get_post_meta($post->ID,'enddate',true) != '0' || (get_post_meta($post->ID,'no_of_coupon',true)==$sellsqlinfo)) {

                    if(get_post_meta($post->ID,'is_expired',true)== '0' || get_post_meta($post->ID,'is_expired',true)== '') {

                        update_post_meta($post->ID,'is_expired','1');

                    }

                }

            }

            $geo_longitude  = get_post_meta($post->ID,'geo_longitude',true);

            $geo_latitude  = get_post_meta($post->ID,'geo_latitude',true);

            $shhiping_address  = get_post_meta($post->ID,'shhiping_address',true);

            $coupon_type = get_post_meta($post->ID,'coupon_type',true);

            $no_of_coupon = get_post_meta($post->ID,'no_of_coupon',true); ?>

            <div class="content_left"> <a href="<?php the_permalink(); ?>">

<?php           if(get_post_meta($post->ID,'file_name',true) != "") { ?>

                    <img src="<?php echo templ_thumbimage_filter(get_post_meta($post->ID,'file_name',true),'&amp;w=330&amp;h=250&amp;zc=1&amp;q=80');?>" alt="" />

<?php           } else { ?>

                    <img src="<?php echo templ_thumbimage_filter(get_template_directory_uri()."/images/no-image.png",'&amp;w=330&amp;h=250&amp;zc=1&amp;q=80');?>" alt="" />

<?php           } ?>

            </a> </div>

            <div class="content_right">

                <span class="title_yellow">Today's Top Cruise Holiday Deal</span> 



                <h3><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></h3>

<?php               if(date("Y-m-d H:i:s")>= date("Y-m-d H:i:s",get_post_meta($post->ID,'coupon_end_date_time',true))){ 

                    if(get_post_meta($post->ID,'is_expired',true)=='1' || get_post_meta($post->ID,'no_of_coupon',true)==$sellsqlinfo) {

                        ?>

                    <div class="i_expire"><?php _e('This deal has','templatic');?><span><?php _e(' expired','templatic');?></span><?php _e('on','templatic');?>

                    <span><?php echo $tardate1;?></span></div>

<?php                   } 

                } else {

                    if(get_post_meta($post->ID,'coupon_end_date_time',true)){ ?>

                        <div id="demo" style="pointer-events:none; cursor:default;">

                            <div id="slider-range-min-var"  ></div>

                        </div>

                        <div class="deal_time_box">

                            <div class="time_line"></div>

                            <div id="countdowncontainer"></div>

                            <script type="text/javascript">

                            var dealexpire=new cdtime("countdowncontainer", "<?php echo $tardate; ?>")

                            dealexpire.displaycountdown("days", formatresults)

                            </script>

                            <div class="fr">

                                <div class="price_main"> <span class="strike_rate"><?php echo get_currency_sym();?><?php echo $current_price;?></span> <span class="rate"><?php echo get_currency_sym();?><?php echo $our_price;?></span> </div>

<?php                               if(get_post_meta($post->ID,'coupon_type',true) == 1) { ?>

                                    <a href="<?php echo get_post_meta($post->ID,'coupon_link',true); ?>" title="<?php _e(BUY_NOW,'templatic');?>" class="btn_buy" target="_blank"><?php _e(BUY_NOW,'templatic');?></a>

<?php                               } else { ?>

                                    <a href="<?php echo get_option('siteurl');?>/?ptype=buydeal&amp;did=<?php _e($post->ID,'templatic'); ?>" title="<?php _e(BUY_NOW,'templatic');?>" class="btn_buy"><?php _e(BUY_NOW,'templatic');?></a>

<?php                               }?>

                            </div>

                        </div>

<?php                   } ?>

<?php               } ?>

                <!-- Rate Summery BOF -->

                <ul class="rate_summery border_bottom">

                    <li class="rate_current_price"><span><?php _e(CURRENT_PRICE,'templatic');?></span> <strong><small><?php echo get_currency_sym();?></small><?php echo $current_price;?></strong></li>

                    <li class="rate_our_price"><span><?php _e(OUR_PRICE,'templatic');?></span> <strong><small><?php echo get_currency_sym();?></small><?php echo $our_price;?></strong></li>

                    <li class="rate_percentage"><span><?php _e(YOU_SAVE,'templatic');?></span> <strong><?php echo @number_format($percentsave,2);?>%</strong></li>



<?php                   if($sellsqlinfo == 0 ) { 

                        $enddate = explode(" ",$tardate); 

                        $curdate = explode(" ",date("F d, Y H:i:s"));

                        $enddate= str_replace(",","",$enddate[1]);

                        $curdate =  str_replace(",","",$curdate[1]);

                        $startdate = explode(" ",$stdate);

                        $strdate = str_replace(","," ",$startdate[1]);

                        $curtime = $enddate - $curdate;

                        $totaltime =  ($enddate - $strdate);

                        $nowremail = $curdate - $strdate; ?>

                        <input type="hidden" value="<?php echo $nowremail ; ?>" name="sellsqlinfo1" id="sellsqlinfo1"/>

                        <input type="hidden" value="<?php  echo ($enddate - $strdate) ; ?>" name="noofcoupon1" id="noofcoupon1"/>

<?php                   } else {  ?>

                      <input type="hidden" value="<?php echo $sellsqlinfo; ?>" name="sellsqlinfo1" id="sellsqlinfo1"/>

                      <input type="hidden" value="<?php echo $no_of_coupon; ?>" name="noofcoupon1" id="noofcoupon1"/>

<?php                   } ?></li>

                </ul>

                <?php   if(get_post_meta($post->ID,'enddate',true) == '0' && get_option('ptttheme_view_opt') != 'Grid View' && (get_post_meta($post->ID,'status',true) == '1' || get_post_meta($post->ID,'status',true) == '2') ) { 



        ?>

        <?php       if(get_post_meta($post->ID,'coupon_type',true) == 1) {?>

                        <a href="<?php echo get_post_meta($post->ID,'coupon_link',true); ?>" title="<?php _e(BUY_NOW,'templatic');?>" class="btn_buy_deal" target="_blank"><?php _e(BUY_NOW,'templatic');?></a>

        <?php       } else { ?>

                        <a href="<?php echo get_option('siteurl');?>/?ptype=buydeal&amp;did=<?php _e($post->ID,'templatic'); ?>" title="<?php _e(BUY_NOW,'templatic');?>" class="btn_buy_deal"><?php _e(BUY_NOW,'templatic');?></a>

        <?php       }

                }?>

                <!-- Rate Summery EOF -->

                <div id="content" class="text_content" ><?php echo "".$post->post_excerpt."";  ?>

                    <a href="<?php the_permalink(); ?>" class="readmore_link"><?php _e(get_option('ptthemes_content_excerpt_readmore'));?></a> </div>

                </div>

                <!-- Social Network Button Like: twitter,facebook,google + one BOF -->

                <div class="share_div index_share_spacer">

                    <div class="twitt_like"><?php templ_show_twitter_button();  ?></div>

                    <div class="googleplus">

                        <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>

                        <script type="text/javascript">

                            gapi.plusone.render(gcontent,"href": "<?php the_permalink(); ?>", "state": "on");

                            gapi.plusone.go("gcontent");

                        </script>

                        <div id="gcontent">

                            <g:plusone href="<?php the_permalink(); ?>" size="medium"></g:plusone>

                        </div>

                    </div>

                    <?php templ_show_facebook_button(); ?>

                    <a href="javascript:void(0);" onclick="show_hide_popup('basic-modal-content');" title="Mail to a friend" class="i_mail b_sendtofriend"><?php _e(MAIL_TO_FRIEND,'templatic');?></a> 

                </div>

                <!-- Social Network Button Like: twitter,facebook,google + one EOF -->

<?php       } else {  ?>

                <div class="content_left">

                    <h3><?php echo _e(NO_RECENT_DEAL,'templatic'); ?></h3>

                </div>

<?php       } 

        }  // foreach loop BOF

    } // 1st IF Condition EOF

/* Home Page Deal Display EOF */ ?>

    </div>

</div>

<!-- main post #end -->

<div class="clear">

  <?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('home_below')) { } else {  }?>

</div>

<?php include_once (TEMPLATEPATH . '/monetize/send_to_friend/popup_frms.php');?>

<?php get_footer(); ?>

2 个答案:

答案 0 :(得分:2)

您的除以零在第61行的包含内。如果您仍然无法找到问题,请发布该代码。

答案 1 :(得分:0)

因此,我们在具有数字划分的代码中要非常小心,因为任何数字除以零都是未定义的。在任何设备中尝试 - 您的手机,计算器等。

这个三元条件可能会有所帮助,但是当$ current_price等于0时,不要强制0(零)为$ percentsave的值。这将破坏应用程序的语义逻辑。

    $percentsave = ($current_price != 0) ? $percent/$current_price : 'undefined';

但是,关于你的查询 - 为什么它在第63行显示,也许你有一个代码包装你的IDE(php特定代码),那部分代码可以在第63行看到。