How to find the difference between event dates in the time line using php?

one text

Actually I am working on the 2002 ( old php project) based on the requirement. So my work is to show the difference between events markers based on the dates by placing some width dynamically in php. So I wrote the code after that it is not even displaying the events markers in the page.

I will provide the code which I wrote for this requirement.

    function getEvents($uid)
{

$timeLineQry = mysql_query("select * from timelines where user_id = $uid and status=1 order by id desc");

    if(mysql_num_rows($timeLineQry) > 0)
    {
        $data='';
        while($tres = mysql_fetch_assoc($timeLineQry))
        {


            $data.='<div class="events-chat" id="timeline'.$tres['id'].'">
<button class="btn btn-success" onclick="addEvent('.$tres['id'].')"> Add Event</button>
<div id="" style="float:right;">
<span style="margin-left: 10px;color: #696767;
cursor: pointer;margin-right: 25px;font-size: 16px;font-weight: bolder;font-family: inherit;" onclick="getTimeLine(\''.$tres['title'].'\',\''.$tres['description'].'\',\''.$tres['id'].'\')">'.$tres['title'].'</span>
<i class="glyphicon glyphicon-trash" onclick="deleteTimeline('.$tres['id'].')"></i>
</div>
<div style="clear:both;margin-bottom:35px;"></div>
<div id="eventBlck'.$tres['id'].'">';
            //echo "select * from events where user_id = $uid and timeline=".$tres['id'];exit;
            $user_exe1 = mysql_query("select * from events where user_id = $uid and timeline=".$tres['id']." order by date asc");
            if(mysql_num_rows($user_exe1) > 0) { 
                $i=1;
                $data.='<div class="events-chat-inner">
                <div class="all-cht-blk">
                <div class="event-border">
                <div class="c-dot" style="float:left;position:absolute;left:-4px;top:-4px;"></div>
                <div class="c-dot" style="float:right;position:absolute;right:-4px;top:-4px;"></div>
                </div>
                
                ';
                while($res = mysql_fetch_assoc($user_exe1))
                {

  //Here is the code I just tried to  subtract the date of one event from date of another event.
                   $datecount = count($res['date']);
                   for($j = 0; $j <= $datecount; $j++){


                   $previous_event_date = strtotime($res['date'][j]);
                   $present_event_date = strtotime($res['date'][j+1]);
                   $distance = $previous_event_date - $present_event_date;
                   $distance = floor($distance/(60 * 60 * 24));

                    $case1 = range(0,20);
                    $case2 = range(1,40);
                    if(in_array($distance,$case1))
                    {
                    $distancestyle = 'width:130px';
                     }
                    elseif(in_array($distance,$case2))
                     {
                     $distancestyle = 'width:180px';
                     }
                     else  
                     {
                     $distancestyle = 'width:230px';
                     }
                      



                    if($i%2==0){$bc='#f45e34';}else if($i%3==0){$bc='#fa454a';}else if($i%4==0){$bc='#3cb54b';}else if($i%5==0){$bc='#03aeac';}else{$bc='#9f388b';}
                    if($i%2==0)
                    {

                        $data.='<div class="event-ct-blk" style='\$distancestyle\'>
                        <h3 onclick="getData('.$res['id'].',
                        \''.str_replace("'","\'",$res['name']).'\',
                        \''.str_replace("'","\'",$res['description']).'\',
                        \''.date('m-d-Y',strtotime($res['date'])).'\');">'.$res['name'].'</h3>
                        <p  onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');">'.$res['description'].' </p>
                        
                        <div class="pointer">
                        <div class="c-dot"></div>
                        <div class="p-strip-2" style="height:125px;"></div>
                        <div class="q-circle-outer"  onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');">
                            <div class="q-circle" style="background: '.$bc.';"></div>
                        </div>
                        <div class="p-strip" style="height:25px;"></div>
                        <div class="c-dot"></div>
                        </div>

                        

                        <p class="q-date"  onclick="getData('.$res['id'].',
                        \''.str_replace("'","\'",$res['name']).'\',
                        \''.str_replace("'","\'",$res['description']).'\',
                        \''.date('m-d-Y',strtotime($res['date'])).'\');"> Date: '.date('M-d-Y',strtotime($res['date'])).' </p>
                        </div>';
                    }
                    else
                    {
                        $data.='<div class="event-ct-blk" style='\$distancestyle\'>
                                                
                        <h3 onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');">'.$res['name'].'</h3>
                        <p  onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');">'.$res['description'].' </p>
                        <div class="pointer">
                        <div class="c-dot"></div>
                        <div class="p-strip" style="height:25px;"></div>
                        <div class="q-circle-outer"  onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');">
                        <div class="q-circle" style="background: '.$bc.';"></div>
                        </div>
                        <div class="p-strip-2" style="height:125px;"></div>
                        <div class="c-dot"></div>
                        </div>
                        <p class="q-date"  onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');"> Date: '.date('M-d-Y',strtotime($res['date'])).' </p>
                        </div>';
                    }
                    $i++;
                }
                $data.='</div></div>';
                
                }
                else
                {
                    $data.='<div class="event-border" style="width:96%;">
                <div class="c-dot" style="float:left;position:absolute;left:-4px;top:-4px;"></div>
                <div class="c-dot" style="float:right;position:absolute;right:-4px;top:-4px;"></div>
                </div><div style="text-align:center;margin-top:78px;font-size: 18px;"><p>No events added.</p></div>';
                }
            
            
            $data.='</div></div>';  
        }
    }
    else
    {
        $data='<div class="events-chat" id="timeline1"> <button class="btn btn-success" onclick="addEvent(1)"> Add Event</button><div style="clear:both;margin-bottom:35px;"></div><div id="eventBlck1"> <div class="event-border"  style="width:96%;">
                <div class="c-dot" style="float:left;position:absolute;left:-4px;top:-4px;"></div>
                <div class="c-dot" style="float:right;position:absolute;right:-4px;top:-4px;"></div>
                </div><div style="text-align:center;margin-top:78px;font-size: 18px;"><p>No events added.</p></div></div></div>';
    }
}//end for loop
    
    return $data;


}

In this code I place the code which I marked as the comments and actually this is the code I have present but after working on this file events are not showing canyou please see the issue in this code or any errors.

Source