Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.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
Javascript 获取单击编号的值以更新单击的数据_Javascript_Php_Jquery - Fatal编程技术网

Javascript 获取单击编号的值以更新单击的数据

Javascript 获取单击编号的值以更新单击的数据,javascript,php,jquery,Javascript,Php,Jquery,我们有一个表单,我们可以单击表单顶部的数字来加载相应的数据,更具体地说,我可以在数据库的表中有4个输入,当我单击数字2(数据的id)时,它就会加载数据。我们这样做了,但是现在我们想要更新单击的数据,直到现在我们还找不到一种方法来获取正确的numberid并将其放在update语句中 下面是单击的函数和UPDATE语句的代码 //教育剧本 $("#updateEdu").click(function () { $("#idE"

我们有一个表单,我们可以单击表单顶部的数字来加载相应的数据,更具体地说,我可以在数据库的表中有4个输入,当我单击数字2(数据的id)时,它就会加载数据。我们这样做了,但是现在我们想要更新单击的数据,直到现在我们还找不到一种方法来获取正确的numberid并将其放在update语句中

下面是单击的函数和UPDATE语句的代码

//教育剧本

                $("#updateEdu").click(function () {
                    $("#idE").css("display", "none");
                    var r = parseInt($("#idE").val(), 10) + 1;
                    $("#idE").val(r);
                });
                $('[data-row-ide]').click(function (e) {
                    e.preventDefault();
                    var fileName = 'addCV.php?idEdu='; //"addCV.php" the name of this file in your project, the "?" starts the GET parameters, idWork= sets the key for the GET parameter  
                    var id = $(this).data('row-ide'); // this gets the id that we stored in the link's data attribute
                    var url = fileName + id; // then we add that id as the value for the "idWork" key
                    window.location = url; // esentially refresh this page with the id set as a GET parameter and make use of the logic we already have to load the info
                });

<?php
                    $username = $_SESSION["username"];
                    if(isset($_POST['updateEdu'])){
                        $parts = parse_url($url);
                            parse_str($parts['query'], $query);
                            $id = $query['idEdu'];

                        $username = $_SESSION['username'];

                        $school = mysql_real_escape_string($_POST["school"]);
                        $degree = mysql_real_escape_string($_POST["degree"]);
                        $website = mysql_real_escape_string($_POST["website"]);
                        $start_date = mysql_real_escape_string($_POST["start_date"]);
                        $end_date = mysql_real_escape_string($_POST["end_date"]);
                        $start_year = mysql_real_escape_string($_POST["start_year"]);
                        $end_year = mysql_real_escape_string($_POST["end_year"]);
                        $degree_description = mysql_real_escape_string($_POST["degree_description"]);

                        if($start_year > $end_year){
                            echo 'The Start Year must be smaller than the End Year!';
                            $id=$id-1;
                            $good = false;
                        }
                        else{
                            $good = true;
                        }
                        if($good == true){
                            $query="UPDATE education
                                    SET school = '$school', degree = '$degree', website = '$website', start_date='$start_date', end_date='$end_date', start_year='$start_year', end_year='$end_year', degree_description='$degree_description'
                                    WHERE id='$id' AND username='$username'";
                            mysql_query($query)or die(mysql_error());
                            if(mysql_affected_rows()>0){
                                echo "<p>Record Updated<p>";
                                echo "<script type='text/javascript'>;
                                        /window.location='addCV.php';
                                      </script>";
                            }
                            else{
                                echo "<p>Error Updating Record<p>";
                                echo "<script type='text/javascript'>;

                                      </script>";
                            }
                        }   
                    }
                    else if(isset($_GET['idEdu'])){
                      // user clicked on one of oue id links to get here
                      // set the id the the value of the GET parameter for key "idWork"
                      $id = $_GET['idEdu'];
                    }
                    else{
                        // Formulate Query
                        // This is the best way to perform an SQL query
                        // For more examples, see mysql_real_escape_string()
                        $query = sprintf("SELECT school,degree,website,start_date,end_date,start_year,end_year,degree_description,id FROM education
                        WHERE username='%s' ORDER BY id LIMIT 1",
                        mysql_real_escape_string($username));

                        // Perform Query
                        $result = mysql_query($query);

                        // Check result
                        // This shows the actual query sent to MySQL, and the error. Useful for debugging.
                        if (!$result) {
                            $message  = 'Invalid query: ' . mysql_error() . "\n";
                            $message .= 'Whole query: ' . $query;
                            die($message);
                        }         
                        // Use result
                        // Attempting to print $result won't allow access to information in the resource
                        // One of the mysql result functions must be used
                        // See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
                        while ($row = mysql_fetch_assoc($result)) {

                            $id = $row['id'];
                        }
                    }

要在jquery中获取elements属性的值,可以使用attr函数,如下所示:

$element.attr'attributeName'

所以你应该改变:

var id = $(this).data('row-ide');
进入

在函数$'[data row ide]'中,单击函数e{}

var id = $(this).attr('row-ide');