Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用内爆显示以前保存在Mysql数据库中的数据_Php_Mysql_Ajax_Pdo_Implode - Fatal编程技术网

Php 使用内爆显示以前保存在Mysql数据库中的数据

Php 使用内爆显示以前保存在Mysql数据库中的数据,php,mysql,ajax,pdo,implode,Php,Mysql,Ajax,Pdo,Implode,我需要知道如何显示数据库中保存的数据,以及如何对治疗信息进行操作。 我需要显示的信息像第一次捕获总是…你能帮我这些吗 以下是截图: 这是在准备将治疗信息保存到数据库时: 另一个是当数据已经在数据库中时: 代码如下: include_once("configs.php"); if (!empty($_POST)) { try{ $diente_id = is_array($_POST['diente_id']) ? implode(', ', $_POST['dient

我需要知道如何显示数据库中保存的数据,以及如何对治疗信息进行操作。 我需要显示的信息像第一次捕获总是…你能帮我这些吗

以下是截图:

这是在准备将治疗信息保存到数据库时:

另一个是当数据已经在数据库中时:

代码如下:

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>

最后,我如何在同一个ajax调用中插入、更新或删除某些处理或全部处理?

正确的答案是,您的操作完全错误。你所拥有的显然是一对多的关系,因此应该使用外键将数据存储在两个单独的表中,以将治疗链接到就诊。请查看此表,了解有关正确数据库关系设计的更多信息。好的,我可以这样做,但如何保存五个,第二个数据库中有六个或更多治疗信息,只需单击提交按钮。。。我没有抓住它…总是保存我的最后一个治疗和放弃前一个…首先,它不是第二个“分贝”。它只是同一数据库中的另一个表。其次,您知道在同一个php脚本中可以有多个insert或update语句,对吗?
$("#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;
});