Warning: A non-numeric value encountered

后端 未结 18 1629
抹茶落季
抹茶落季 2020-11-22 06:15

Recently updated to PHP 7.1 and start getting following error

Warning: A non-numeric value encountered in on line 29

Here is wha

相关标签:
18条回答
  • 2020-11-22 06:19

    Try this.

    $sub_total = 0;
    

    and within your loop now you can use this

    $sub_total += ($item['quantity'] * $product['price']);
    

    It should solve your problem.

    0 讨论(0)
  • 2020-11-22 06:19
    $sn = 0;//increment the serial number, then add the sn to job
    for($x = 0; $x<20; $x++)
    {
    $sn++;
    $added_date = "10/10/10";
    $job_title = "new job";
    $salary = $sn*1000;
    $cd = "27/10/2017";//the closing date
    $ins = "some institution";//the institution for the vacancy 
    $notes = "some notes here";//any notes about the jobs
    
    $sn_div = "<div class='sn_div'>".$sn."</div>";
    $ad_div = "<div class='ad_div'>".$added_date."</div>";
    $job_div = "<div class='job_div'>".$job_title."</div>";
    $salary_div = "<div class='salary_div'>".$salary."</div>";
    $cd_div = "<div class='cd_div'>".$cd."</div>";//cd means closing date
    $ins_div = "<div class='ins_div'>".$ins."</div>";//ins means institution
    $notes_div = "<div class='notes_div'>".$notes."</div>";
    
    
    /*erroneous line*/$job_no = "job"+$sn;//to create the job rows
    $$job_no = "<div class='job_wrapper'>".$sn_div.$ad_div.$job_div.$salary_div.$cd_div.$ins_div.$notes_div."</div>";
    
    echo $$job_no;//and then echo each job
    
    }
    

    that's the code I had which looped and created new html div elements. The code worked fine and the elements were formed, but i got the same warning in the error_log.

    After reading the useful other answers, I figured that I was summing up a string and a number in the erroneous line. So I changed the code at that line to

    /*erroneous line*/$job_no = "job"&&$sn;//this is the new variable that will create the job rows
    

    Now the code works as earlier but with no warnings this time. Hope this example would be useful to someone.

    0 讨论(0)
  • 2020-11-22 06:20

    I encountered the issue in phpmyadmin with PHP 7.3. Thanks @coderama, I changed libraries/DisplayResults.class.php line 855 from

    // Move to the next page or to the last one
    $endpos = $_SESSION['tmpval']['pos']
        + $_SESSION['tmpval']['max_rows'];
    

    into

    // Move to the next page or to the last one
    $endpos = (int)$_SESSION['tmpval']['pos']
        + (int)$_SESSION['tmpval']['max_rows'];
    

    Fixed.

    0 讨论(0)
  • 2020-11-22 06:21

    This was happening to me specifically on PHPMyAdmin. So to more specifically answer this, I did the following:

    In File:

    C:\ampps\phpMyAdmin\libraries\DisplayResults.class.php
    

    I changed this:

    // Move to the next page or to the last one
    $endpos = $_SESSION['tmpval']['pos']
        + $_SESSION['tmpval']['max_rows'];
    

    To this:

    $endpos = 0;
    if (!empty($_SESSION['tmpval']['pos']) && is_numeric($_SESSION['tmpval']['pos'])) {
        $endpos += $_SESSION['tmpval']['pos'];
    }
    if (!empty($_SESSION['tmpval']['max_rows']) && is_numeric($_SESSION['tmpval']['max_rows'])) {
        $endpos += $_SESSION['tmpval']['max_rows'];
    }
    

    Hope that save's someone some trouble...

    0 讨论(0)
  • 2020-11-22 06:22
    $sub_total_price = 0; 
    
    foreach($booking_list as $key=>$value) {
            $sub_total_price += ($price * $quantity); 
    }
    
    echo $sub_total_price;
    

    it's working 100% :)

    0 讨论(0)
  • 2020-11-22 06:25

    Make sure that your column structure is INT.

    0 讨论(0)
提交回复
热议问题