简体   繁体   English

如何在 MySQL 中存储数据?

[英]How to store data in MySQL?

I am writing a script that can create a table and dynamically add new rows using mysql.我正在编写一个脚本,它可以创建一个表并使用 mysql 动态添加新行。

Two column values will this code.两列值将使用此代码。 I tried to use an Array but don't know how to proceed.我尝试使用数组,但不知道如何继续。

Here is my web page:这是我的网页:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> Dynamically </title>
<style type="text/css">
    form{
        margin: 20px 0;
    }
    form input, button{
        padding: 5px;
    }
    table{
        width: 100%;
        margin-bottom: 20px;
        border-collapse: collapse;
    }
    table, th, td{
        border: 1px solid #cdcdcd;
    }
    table th, table td{
        padding: 10px;
        text-align: left;
    }
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
        $(".add-row").click(function(){
            var name = $("#name").val();
            var email = $("#email").val();


            var markup = "<tr><td><input type='checkbox' name='record'></td><td>" + name + "</td><td>" + email + "</td></tr>";



        if ($('#name').val() == "") 
            {
            alert('Please Enter the Name');
            $('#name').focus();
            }
            else if 
             ($('#email').val() == "") 
            {
            alert('Please Enter the email');
            $('#email').focus();
            }
            else
            {
            $("table tbody").append(markup);


            $("#name").val("");
            $('#email').val('');
            $('#name').focus();

            }

        });

        // Find and remove selected table rows
        $(".delete-row").click(function(){
            $("table tbody").find('input[name="record"]').each(function(){
                if($(this).is(":checked")){
                    $(this).parents("tr").remove();
                }
            });
        });
    });    
</script>
</head>
<body>



        <input type="text" id="name" placeholder="Name">
        <input type="text" id="email" placeholder="Email Address">
        <input type="submit" class="add-row" value="Add Row">

    </form>
    <table>
        <thead>
            <tr>
                <th>Select</th>
                <th>Name</th>
                <th>Email</th>
            </tr>
        </thead>
        <tbody>
            <!--<tr>
                <td><input type="checkbox" name="record"></td>
                <td></td>
                <td></td>
            </tr>-->
        </tbody>
    </table>
    <button type="button" class="delete-row">Delete Row</button>
<button onclick="myFunction()">Click me</button>
</body> 
</html>   

You just wrote some kind of client-side Javascript application that for example runs inside a web browser.您刚刚编写了某种客户端 Javascript 应用程序,例如在 Web 浏览器中运行。 One possibility is to connect that application to a server that exposes an API to request some kind of data from and display it inside the application table.一种可能性是将该应用程序连接到公开 API 的服务器,以从中请求某种数据并将其显示在应用程序表中。

I would suggest taking for example a look into Angular and its hero-examples: Angular heroes to get an understanding of modern web application development.我建议以查看 Angular 及其英雄示例为例: Angular 英雄以了解现代 Web 应用程序开发。 As next step you could take a look into NodeJs to understand how a simple server-side API is build and how to store data into MySQL or MongoDB.作为下一步,您可以查看 NodeJs 以了解如何构建简单的服务器端 API 以及如何将数据存储到 MySQL 或 MongoDB。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM