使用implode显示先前保存在Mysql数据库中的数据

时间:2014-03-21 00:43:25

标签: php mysql ajax pdo implode

我需要知道如何显示保存在数据库中的数据并对治疗信息采取措施。 我需要像第一次捕获一样显示信息......你能帮我解决这些问题吗?

以下是捕获:

这是处理信息准备保存到数据库时: Treatment prepare to save into DB

另一个是当数据已经在数据库中时: treatments after saved into DB

这里是代码:

include_once("configs.php");
if (!empty($_POST)) {
    try{
        $diente_id = is_array($_POST['diente_id']) ? implode(', ', $_POST['diente_id']) : $_POST['diente_id'];
        $cara = is_array($_POST['cara']) ? implode(', ', $_POST['cara']) : $_POST['cara'];
        $tratamiento = is_array($_POST['tratamiento']) ? implode(', ', $_POST['tratamiento']) : $_POST['tratamiento'];
        $stmt = $conn->prepare('INSERT INTO ODONTOGRAMA (diente_id, cara, tratamiento, id_paciente) 
        VALUES (:diente_id, :cara, :tratamiento, :id_paciente)');   
        $stmt->bindParam(':diente_id', $diente_id);
        $stmt->bindParam(':cara', $cara);
        $stmt->bindParam(':tratamiento', $tratamiento);
        $stmt->bindParam(':id_paciente', $_POST['id_paciente']);
        $stmt->execute();
        echo 'Registro ingresado correctamente.';                               
    }
    catch (PDOException $e) 
    {
        error_log($e->getMessage());
        die($e->getMessage());
    }
}

页面中的表单:

<form name="dentista" id="dentista" method="post">
        <table class="table table-striped table-condensed">
            <thead>
                <tr>
                    <th><?php $translate->__('Date'); ?></th>
                    <th><?php $translate->__('ID'); ?></th>
                    <th><?php $translate->__('Aplicar a'); ?></th>
                    <th><?php $translate->__('Treatment'); ?></th>
                    <th><?php $translate->__('Actions'); ?></th>
                </tr>
            </thead>   
            <tbody>
                <?php 
                    $sql = $conn->prepare("SELECT id_odont, diente_id, cara, tratamiento , DATE_FORMAT(f_odonto, '%d %M %Y') AS f_odonto FROM ODONTOGRAMA WHERE id_paciente=? order by id_odont DESC");
                    $sql->execute(array($_GET['id_paciente']));
                    while($row = $sql->fetch(PDO::FETCH_ASSOC)) {
                ?>
                <tr>
                    <td><?php echo $row['f_odonto']; ?></td>
                    <td><?php echo $row['diente_id']; ?></td>
                    <td><?php echo $row['cara']; ?></td>
                    <td><?php echo $row['tratamiento']; ?></td>
                    <td></td>
                </tr><?php } ?>
            </tbody>
            <tbody data-bind="foreach: tratamientosAplicados">
                <tr>
                    <td></td>
                    <td><span data-bind="text: diente.id" id="diente.id"></span><input type="hidden" name="diente_id[]" data-bind="value: diente.id" /></td>
                    <td><span data-bind="text: cara" id="cara"></span><input type="hidden" name="cara[]" data-bind="value: cara" /></td>
                    <td><span data-bind="text: tratamiento.nombre" id="tratamiento"></span><input type="hidden" name="tratamiento[]" data-bind="value: tratamiento.nombre" /></td>
                    <td>
                        <a href="#" data-bind="click: $parent.quitarTratamiento" class="btn btn-danger">
                            <i class="icon-trash icon-white"></i>
                        </a>
                    </td>
                </tr>
            </tbody>
        </table>
    <input type="hidden" name="id_paciente" value="<?php echo $id_paciente; ?>" />
    <input type="submit" class="btn btn-primary" value="<?php $translate->__('Save Odontogram'); ?>" />
</form>
<div id="loading" style="display:none;"><img src="img/ajax-loaders/loading4.gif" /></div>

JS:

$("#dentista").submit(function(){
$.ajax({
type:"POST",
url:"include/odonto.php?ts=" + new Date().getTime(),
dataType:"text",
data:$(this).serialize(),
beforeSend:function(){
$("#loading").show();
},
success:function(response){
$("#loading").hide();
} 
})
return false;
});

最后,我怎样才能在同一个ajax调用中进行插入,更新或删除某些处理或全部?

0 个答案:

没有答案