Jump to content

When asrray value is 0 use last value not 0


Paulqvz

Recommended Posts

Hi all. I call a stored proc from mysql and show it in php html.

 

function CreateTableRow($RowItem){
    $rowHtml = "<tr border: 1px solid black;
  border-collapse: collapse;>";
    $array = get_object_vars($RowItem);
    foreach($array as $keyItem => $value){
        $rowHtml .= "<td border: 1px solid black;
  border-collapse: collapse;>{$value}</td>";
    }
    $rowHtml .= "</tr>";
    return $rowHtml;
}

This works great, but i am now stumped on how to get it to when it finds a cell with 0 value to use previous value thats not 0.

I tried fixing it in mysql with stored proc but it does not make all 0 with previous value.

Here is my sql.

SELECT 
  GROUP_CONCAT(
DISTINCT CONCAT(

 'case 
 when  
sum(if(t.ipDATE = ''',ipDATE,''', t.market_value_1, 0))  = 0 
and SUM(IF(t.ipDATE = date_sub(''',ipDATE,''',interval 1 day), t.market_value_1, 0)) = 0
then
round(SUM(IF(t.ipDATE = date_sub(''',ipDATE,''',interval 2 day), t.market_value_1, 0)),6)

 when 
sum(if(t.ipDATE = ''',ipDATE,''', t.market_value_1, 0))  = 0 
then 
round(SUM(IF(t.ipDATE = date_sub(''',ipDATE,''',interval 1 day), t.market_value_1, 0)),6)




else 
round(sum(if(t.ipDATE = ''',ipDATE,''', t.market_value_1, 0)),6) end 
AS `',CONCAT(ipDATE),'`'

    ) 
    ORDER BY YEAR(ipDATE) ASC,
    MONTH(ipDATE) ASC,DAY(ipDATE) ASC
  )  INTO @sql

But this does not work for when there a 6 dates in a row with 0 values

Link to comment
Share on other sites

At minimum, I think we will need the structure of your table(s). 

We need some typical/sample data

Need to know the structure of a $RowItem

You need to further explain what you mean by "when it finds a cell with 0 value to use previous value thats not 0."  What is "it".  How rules exactly, will dictate a value to replace a "0" and why is that needed?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.