如何在主要是javaScript和JQuery的文档中编写SQL


How to do SQL write in document that is largely javaScript and JQuery

我试图找出如何得到一个SQL数据库写入我的文件,主要是javaScript和JQuery。我在网上找到了一些php信息,但是我很难把php与其他所有的东西一起放入我的代码中。我试图利用一个数组,我把用户输入的信息从一个html表,并调用一个方法,使用数组作为参数。我已经使我的整个文件一个php文件,但我有麻烦弄清楚在没有我的bigTableRows数组超出范围或其他运行时错误消息的情况下把php <?php ?>分隔符放在哪里。在我弄清楚这一点后,我需要做一个MS SQL写。现在,我看到这个错误消息,但没有表。第83行是<?php之后的行,在那里我有echo(bigTableRows[0];

Parse error: syntax error, unexpected '[' in E:'visE'jqproject'web'BigTable.php on line 83 

如果我拿走[0]部分,我得到一个syntaxError,但看到表ok:

missing; before statement.

是这样的:

BigTable.php:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<meta content="utf-8" http-equiv="encoding"/> 
    <title>Big Table</title>

    <script type="text/javascript" src="js/jquery-1.11.0.js"></script>
    <script type="text/javascript">
        //Used to make row editable or not
        $(document).ready(function () {
      $('.editbtn').click(function () {
          var currentTD = $(this).parents('tr').find('td');
          if ($(this).html() === 'Edit') {                  
              $.each(currentTD, function () {
                  $(this).prop('contenteditable', true);
              });
          } else {
             $.each(currentTD, function () {
                  $(this).prop('contenteditable', false);
              });
          }
          //change button text when hit it between edit/save
          $(this).html($(this).html() === 'Edit' ? 'Save' : 'Edit');
          var bigTableRows = getBigTableRowData(0); //first row
          console.log("bigTableRows other", bigTableRows);
          InsertData(bigTableRows);
      });

    function InsertData($theDataArr)
    {
        //The php part below isn't working**********************            
        $bandY = $theDataArr[0];//$_POST['bandY'];
        $bandM = $theDataArr[1];//$_POST['bandM'];
        $bandC = $theDataArr[2];//$_POST['bandC'];
        $bandK = $theDataArr[3];//$_POST['bandK'];
        $comment = $theDataArr[4];//$_REQUEST['comment'];
        console.log("bandY php: ", $bandY);
        console.log("bandM php: ", $bandM);
        console.log("bandC php: ", $bandC);
        console.log("bandK php: ", $bandK);
        console.log("comment php: ", $comment);
        <?php //where to put this and still have variable info******
        echo(bigTableRows[0]);
            //console.log("bandY php: ", $bandY);
            //console.log("bandM php: ", $bandM);
            //console.log("bandC php: ", $bandC);
            //SQL dB write to follow after I can access data**************
        ?> 
    }
  });
    </script>
    <script>
     function getBigTableRowData(rowNum)
     {
        //I just need row data for the one that was just edited/saved******
        var rowText = $("#bigTable tbody tr:eq(" + rowNum + ") td").map(function() {
        // Find all of the table cells on this row.
            // Determine the cell's row text 
            return $(this).text();
        }).get();    
        return rowText;
     }
    </script>       
</head>
<body>
    <div class="form">
        <p>
            <h1> Visual Evaluation Entry Table </h1>
        </p>
    </div>
<table id="bigTable" border="1">
    <thead>
        <tr>
            <th id="edit" class="col3">Edit/Save</th><th id="bandY" class="col3">Bands @263mm Y</th><th id="bandM" class="col3">Bands @263mm M</th><th id="bandC" class="col3">Bands @263mm C</th><th id="bandK" class="col3">Bands @263mm K</th><th id="Comments" class="col3">Comments</th></tr>
    </thead>
    <tbody>
        <tr>
            <td><button class="editbtn">Edit</button></td>  
            <td name="bandY" contenteditable="false"></td> <!-- //Row 0 Column 1-->
            <td name="bandM" contenteditable="false"></td>  <!--//Row 0 Column 2-->
            <td name="bandC" contenteditable="false"></td>  <!--//Row 0 Column 3-->
            <td name="bandK" contenteditable="false"></td>  <!--//Row 0 Column 4-->
            <td name="comment" contenteditable="false"></td>  <!--//Row 0 Column 4-->
        </tr>
    </tbody>
</table>
</body>
</html>

我发现的一些例子是:PHP SQL编写,和将HTML表数据放入数组

我知道,如果我拿走<?php分隔符,它会运行ok(减去echo)(并访问数组数据),但我需要他们做php部分。如果我对这件事的看法有任何偏差,我肯定是有偏差的,请随时告诉我。我对xml/html有一点php经验,但我正在学习javaScript和JQuery,我以前从未尝试过把它们放在一起。

好的,我真的试图在这里是建设性的,我从来没有在PHP上使用过微软SQL连接器,但看文档是非常类似于MySQL连接器(我认为是这样的)。

因此,您需要首先创建连接,如果您这样做,您需要迭代数据集以获取数据或将数据传递给数组。

在你的示例代码中,我看到JS与PHP的混合,这是不对的。

你唯一需要做的就是阅读这个链接:这个链接!

1。—创建连接。2.-执行查询。3.-获取数据集到一个数组(这只是我个人的建议)。4.-在PHP中使用数据或将其保存在像这样的变量中。

<?php
    echo "var val = " . $myArray[0][0] . ";"; /** Here you are "printing" the variable declaration into the HTML document. **/
?>

事实上,如果你想让JSON中的数据在javascript对象中使用,你可以这样做。

<?php
    echo "var myObj = '" . json_encode($myArray) . "';";
?>