How to add the option tag inside php table and pass the selected value to mysql db without submit button?

I have created an escalation system where user uploads .csv file and user can view the uploaded details in web page.

An option tag will be displayed in each row with the below options:

  • First level Escalation sent
  • Second level Escalation sent
  • Third level Escalation sent.

I simply want to store the selected item to save in the DB, so the other agent who use the system can see which level escalation has been sent for each complaints.

Here is my code. I am unable to store the option item in DB. Ex: When I select "*First level Escalation sent" it doesn't display to others. Pls help

<table width="100%" border="1" cellpadding="1" cellspacing="1" style="font-size:10.5px; font-family:verdana;" >
<tr> 	
    <td>Name</td>
    <td>SR Number</td>
    <td>Service Impact</td>
    <td>Customer Ref No</td>
    <td>Reported Date and Time</td>
    <td>Issue</td>
    <td>Pending Reason as per TAC</td>
    <td>Expected Time for Resolution</td>
    <td>TAC Agent</td>
    <td>Cx Contact</td>
    <td>Elapsed Time</td>
    <td>Archive</td>
    <td>Send Email</td>
    <td>Comment</td>
</tr>

<?php
while ($ccs=mysqli_fetch_assoc($records)) {
    $A=$ccs['Name'];
    $B=$ccs['SRNumber'];
    $C=$ccs['ServiceImpact'];
    $D=$ccs['CustomerRefNo'];
    $E=$ccs['ReportedDateAndTime'];
    $F=$ccs['Issue'];
    $G=$ccs['PendingReasonAsPerTAC'];
    $H=$ccs['ETR'];
    $I=$ccs['TACAgent'];
    $J=$ccs['Cxcontact'];
  
    echo("   
	<tr class='options'>
        <td>$A</td>
	<td>$B</td>
	<td>$C</td>
	<td>$D</td>
        <td>$E</td>
	<td>$F</td>
	<td>$G</td>
	<td>$H</td>
	<td>$I</td>
	<td>$J</td>
	<td>
     ");
    date_default_timezone_set('Asia/Colombo');
    $the_time = date('H:i');
    $hours = "00";
    $minutes = "00";
    $seconds = "00";
			
    $new_time=$E;
    $datetime1 = new DateTime($the_time);	
    $datetime2 = new DateTime($new_time);
    $interval = $datetime2->diff($datetime1);			
    $hours=$interval->format('%h');
    $minutes= $interval->format('%i');
    $seconds= $interval->format('%s');

    echo $hours." Hours  ".$minutes."  Minutes ".$seconds." Seconds</br></br>";
    echo("
    <td><a href=Escalation_Display.php?delete=$B>Archive</a></td>
    <td><a href=Escalation_Display.php?ID=$B>Email</a> </td>  
    <td>
        <select id='select'>
            <option value='1'>select</option>
            <option value='2'>First level Escalation sent</option>
            <option value='3'>SECOND</option>
            <option>THIRD</option>
            <option>CLOSURE NOT SENT</option>
        </select>
    </td>
</tr>
    ");
}
?>
</table>

Answers


Make one column name Comment in table from where you are fetching record ($records). I tried. I gave you how to do. But, please make changes in if condition in <select></select> if required.

<?
    .
    .
    while ($ccs=mysqli_fetch_assoc($records)){
        $B=$ccs['SRNUMBER']; I assumed column 'id' (Primary Key and auto-incremented). Change with your column name.
        $escValue=$ccs['Comment']; I assumed column 'escalation_value' as i wrote above.
        .
        .
        .
        ?><td>
            <select id='selectEscalation'>
                <option hidden>Select</option>
                if($escValue != 1) {
                <option value="1."-".$B;">First level Escalation sent</option>
                }
                if($escValue != 2 && $escValue == 1) {
                <option value="2 . "-" . $B;">Second level Escalation sent</option>
                }
                if($escValue != 3 && $escValue==2) {
                <option value="3."-".$B;">Third level Escalation sent</option>
                }
                if($escValue == 3) {
                <option>CLOSURE NOT SENT</option>
                }
            </select>
        </td>
    </tr>");
    }
    ?>
</table>

<script>
    $('#selectEscalation').change(function(){
        var EscalationValue=$('#selectEscalation').val();
        $.ajax({url:"Ajax-submitEscalation.php?EscalationValue="+EscalationValue,cache:false,success:function(result){
            alert("Escalation Sent");
        }});
    }); 
</script> 

Ajax-submitEscalation.php

<?
// split the contents of $_POST['data'] on a hyphen, returning at most two items
list($data_value, $data_id) = explode("-", $_POST['EscalationValue'], 2);

//escalation_value column name as i wrote above.
$Query="UPDATE TableName SET Comment='$data_value' WHERE SRNUMBER='$data_id'"

?>

Need Your Help

Azure Web App Performance Test

azure azure-web-sites

Noticed a Performance Test feature on Azure Web Apps.

copy vs deepcopy: semantics

python python-3.x copy deep-copy

My class represents states of various systems. Each instance has two attributes: one is a container shared between all the states of the same system, and the other is a container that is unique to ...