简体   繁体   English

从JSFiddle向JS代码添加MySQL请求

[英]Adding MySQL requests to JS Code from JSFiddle

First and foremost, I want to say how amazing this community is. 首先,我想说一下这个社区有多神奇。 I've been reading and using this place for a bit now to get answers to a plethora of questions. 我一直在阅读和使用这个地方,以获取许多问题的答案。

I'm currently working on building a student list (never really built a system before) system for our company using Bootstrap 3. I've got the meat of it worked out and have found this awesome JSFiddle by user Mils (many thanks) that does what I need it to in terms of adjusting data dynamically, which would be ideal for what we want. 我目前正在使用Bootstrap 3为我们的公司建立一个学生名单系统(以前从未真正建立过系统)。我已经弄清楚了它的内容,并由用户Mils找到了这个很棒的JSFiddle(非常感谢),就动态调整数据而言,确实可以满足我的需求。

http://jsfiddle.net/NfPcH/645/ http://jsfiddle.net/NfPcH/645/

My question is: how can I alter this so that it pulls data from a MySQL database I've created, and how do I alter it so that when adding/editing a row, it writes it to the db? 我的问题是:如何更改它以便从我创建的MySQL数据库中提取数据,以及如何更改它以便在添加/编辑行时将其写入数据库? I have a students.php page I created that pulls in the information as such: 我有一个我创建的students.php页面,其中包含如下信息:

 // Prepare SQL Query
$STM = $db->prepare("SELECT `student_firstname`, `student_lastname`, `student_class`, `year` FROM students ORDER BY student_firstname");
// For executing prepared statement
    $STM->execute();
// Fetch records
$STMrecords = $STM->fetchAll();
foreach($STMrecords as $row)
{
    echo"<tr>";
    echo"<td><a href='#' id='student-firstname' data-type='text' data-pk=".$row['student_firstname']."</td>";
    echo"<td>".$row['student_lastname']."</td>";
    echo"<td>".$row['student_class']."</td>";
    echo"<td>".$row['year']."</td>";
    echo"</tr>";
}

But this doesn't go hand-in-hand with the aforementioned JSFiddle, as it only posts the data on the page. 但是,这与前面提到的JSFiddle并不一致,因为它仅将数据发布在页面上。

Thanks, everyone! 感谢大家!

You need to redirect the get request in the JSFiddle to you php script. 您需要将JSFiddle中的get请求重定向到您的php脚本。 And the php script needs to return something on the expected format. 并且php脚本需要以预期格式返回某些内容。

At the end of the fiddle there is a couple of mocks, there you can see how the output from the php script should be formatted. 小提琴的结尾有几个模拟,您可以看到如何格式化php脚本的输出。

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

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