user2402315
user2402315

Reputation: 3

Null value is returned from mysql through php

i am working on a project, in which i need to send two alerts through email. i have implemented one email alert and its working fine and i'm getting status message as completed after successfull delivery of email but for the second one i have added one more column as service_status. although the email functionality is working fine but its doesnot showing completed instead its showing null or empty value, but the value in database is "completed"... Here is my peice of code where i need to show the completed result

  <?php 
if(count($det)){
?>

<?php for($i=0;$i<count($det);$i++)
{?>
 <tr class="rowvalues">
<td rowspan="2" class="bottomcolor">
        <input  type="checkbox"  name="list[]"  value="<?php echo $det[$i]['customer_id']; ?>" /></td>
<td rowspan="2" class="bottomcolor"><?php echo $det[$i]['customer_title'].".".$det[$i]['customer_surname']; ?></td>
<td rowspan="2" class="bottomcolor"><?php echo $det[$i]['vehicle_regno']; ?></td>
<td>Reminder1</td>
<td><?php
        if ($det[$i]['reminder1_duedate'] != '0000-00-00'){
         echo date('d/m/Y',strtotime($det[$i]['reminder1_duedate']));}else{echo '00/00/0000';} ?></td>
<td><?php if ($det[$i]['reminder1_duedate'] != '0000-00-00'){ echo  date('d/m/Y',strtotime($det[$i]['reminder1_duedate'].'- 28 days'));}else{echo '00/00/0000';} ?></td>
<td><?php if ($det[$i]['reminder1_duedate'] != '0000-00-00'){ echo  date('d/m/Y',strtotime($det[$i]['reminder1_duedate'].'- 14 days'));}else{echo '00/00/0000';} ?></td>
<td><?php if ($det[$i]['reminder1_duedate'] != '0000-00-00'){ echo  date('d/m/Y',strtotime($det[$i]['reminder1_duedate'].'- 2 days'));}else{echo '00/00/0000';} ?></td>
<td><?php echo isset($det[$i]['reminder1_status'])?($det[$i]['status']=='c')?'Completed':'Pending':'';?>           </td>
<td rowspan="2" class="bottomcolor"><a href="<?php echo base_url();?>preview/view_vehicle.php?vid=<?php echo $det[$i]['customer_id'];?>" rel="facebox"><img src="<?php echo base_url();?>images/view.gif" alt="View"/></a>
       <a style="text-decoration:none;" href="<?php echo base_url();?>index.php/vehicles/edit_mot/<?php echo $det[$i]['customer_id'];?>" title="Edit"> <img src="<?php echo base_url();?>images/edit.gif" alt="search"/></a> <a style="text-decoration:none;" href="<?php echo base_url();?>index.php/vehicles/view/delete/<?php echo $det[$i]['customer_id'];?>" onclick="return confirm('Are you sure you want to delete this Vehicle Details?');" title="Delete">
        <img src="<?php echo base_url();?>images/delete.gif" alt="delete"/></a></td>
    </tr>
    <tr>
    <td class="bottomcolor">Reminder 2</td>
     <td class="bottomcolor"><?php
        if ($det[$i]['reminder2_duedate'] != '0000-00-00'){
         echo date('d/m/Y',strtotime($det[$i]['reminder2_duedate'])); }else{echo '00/00/0000';}?></td>
    <td class="bottomcolor"><?php if ($det[$i]['reminder2_duedate'] != '0000-00-00'){ echo  date('d/m/Y',strtotime($det[$i]['reminder2_duedate'].'- 28 days'));}else{echo '00/00/0000';}?></td>
    <td class="bottomcolor"><?php if ($det[$i]['reminder2_duedate'] != '0000-00-00'){ echo  date('d/m/Y',strtotime($det[$i]['reminder2_duedate'].'- 14 days'));}else{echo '00/00/0000';}?> </td>
    <td class="bottomcolor"><?php if ($det[$i]['reminder2_duedate'] != '0000-00-00'){ echo  date('d/m/Y',strtotime($det[$i]['reminder2_duedate'].'- 2 days'));}else{echo '00/00/0000';}?> </td>
    <td class="bottomcolor"><?php echo isset($det[$i]['reminder2_status'])?($det[$i]['service_status']=='c')?'Completed':'Pending':'';?>          </td>
    </tr>

             <?php } 
          }
     else{ echo '<div class="row"><p  style="text-align:center;"><strong>No records found</strong></p></div>'; 
    } ?>

  </table>      

The problem is from this line of code

        <td class="bottomcolor"><?php echo isset($det[$i]['reminder2_status'])?($det[$i]['service_status']=='c')?'Completed':'Pending':'';?>          </td>

This is returning empty or null value

Upvotes: 0

Views: 177

Answers (2)

Kiran Tangellapalli
Kiran Tangellapalli

Reputation: 172

Its probably because the $det[$i]['reminder_status'] variable is undefined. Check the $det variable in which you call the mysql query. make sure the reminder_status column is returned through the mysql.

Upvotes: 1

km6zla
km6zla

Reputation: 4877

Your problem is your nested ternary operators. If you are intent on nesting them at least use parenthesis to organize them.

<?php echo 
    (isset($det[$i]['reminder2_status'])?
        ($det[$i]['service_status']=='c' ? 'Completed' : 'Pending' )
        : '' );?>

If it returns an empty string it means that $det[$i]['reminder2_status'] is not set. There is no way for it to return a null though.

Upvotes: 1

Related Questions