兄弟姐妹如何在每个行上都有按钮的表中工作

时间:2017-05-25 16:57:31

标签: javascript php json

兄弟姐妹是如何工作的? 我有一个表格用html填充dinamically,有一个按钮到wach行结束。我想将用户重定向到另一个页面,但请记住点击按钮的行的ID。我正在使用json,php,slim框架,pdo,phpmyadmin。提前谢谢。

<script type="text/javascript">
     $(document).ready(function()
     {
        $.ajax(
        {
            url: path+'/proyects/all',
            type: 'get',
            dataType: "json",
            success: function(json)
            {
                console.log(json);

                if (json.success)
                {
                    $.each(json.proyects, function( index, value ) {

                      $('#proyecs').append('<tr><td>'+value.idproyect+'</td><td>'+value.pdescription+'</td><td>'+value.presponsible+'</td><td>'+value.pdateini+'</td><td>'+value.pdatefin+'</td><td>'+value.pestatus+'&#37</td><td><button type="button" class="btn btn-default">Details</button></td></tr>');
                    });
                }
                else
                {
                    Materialize.toast(json.message, 5000, 'red accent-4');
                }
            },
            error : function(e, settings, exception)
            {
                Materialize.toast("Oops! an error has ocurred", 5000, 'red accent-4');
            }
        });
    });
</script>

$app->get('/proyects/all', function () use($servername, $dbname, $dbuser, $dbpassword)
{

$response = array();

try
{
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbuser, $dbpassword);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $stmt = $conn->prepare("SELECT * FROM proyects");

    if ($stmt->execute())    {
        $result = $stmt->fetchAll();
    }

    $conn = null;

    if(!empty($result))
    {
        $response['proyects'] = array();
        foreach ($result as $key => $value)
        {
            $response['proyects'][$key] = $value;

        }
        $response['success'] = true;

        echo json_encode($response);
        return;
    }
    else
    {
        $response['success'] = false;
        $response['message'] = "Proyects not found";

        echo json_encode($response);
        return;
    }

}
catch(PDOException $e)
{
    $response['success'] = false;
    $response['message'] = $e->getMessage();

    echo json_encode($response);
    return;
}
});

0 个答案:

没有答案