[英]How do I populate form fields on a page from a database based on the page url?
Hello first I'd like to say, please excuse my ignorance to this all, as I'm very new to this all. 您好,首先我想说的是,请原谅我的无知,因为我对此并不陌生。 I just started and still trying to understand this.
我刚刚开始,但仍在尝试了解这一点。
So far I have a database set up and I'm trying to retrieve values from a database to fill in a form on a page when it loads. 到目前为止,我已经建立了一个数据库,并且正在尝试从数据库中检索值,以便在加载时在页面上填写表格。 The record or row/values that need to be retrieved from a database depend on the page's URL.
需要从数据库中检索的记录或行/值取决于页面的URL。
I'm ok with html and css but still trying to learn more about jquery, JavaScript, sql, php and so on and so forth. 我对html和css没问题,但仍然尝试了解有关jquery,JavaScript,sql,php等的更多信息。 I realize I have a ways to go and honestly some of the guides and tutorials online are kind of confusing because everyone has a different way of coding.
我意识到我有一个路要走,说实话,在线上的一些指南和教程有点让人困惑,因为每个人都有不同的编码方式。 So I'm a bit confused.
所以我有点困惑。
I've included a simple chart to breakdown what I'm trying to do. 我提供了一个简单的图表来细分我要尝试执行的操作。
If someone could point me in the right direction I'd be really grateful! 如果有人能指出正确的方向,我将不胜感激! Thanks.
谢谢。
If I understand you well, you want to setup a form and populate some fields of this form with a query forms a database, the primary key of the record being relative to the url. 如果您对我的理解很好,那么您希望设置一个表单,并使用查询表单数据库填充该表单的某些字段,记录的主键是相对于url的。
The first step is to build the url, you can pass some parameters to an url by adding a ?
第一步是构建url,您可以通过添加
?
将一些参数传递给url ?
at the end of the url followed by the parameter name, the =
sign and the parameter value. 在网址末尾,然后是参数名称,
=
符号和参数值。 If you have more than one parameter, you should separate each parameter with the sign &
. 如果您有多个参数,则应使用符号
&
分隔每个参数。
So your url could be something like this : www.examplesite.com/page&.html?key=key_A1
因此您的网址可能是这样的:
www.examplesite.com/page&.html?key=key_A1
Then, you'll have to choose if you want to build the page on the server side with a language like php , in which case you retrieve the parameter, query the database, build the html form and send it to the client. 然后,您必须选择是否要使用php之类的语言在服务器端构建页面,在这种情况下,您需要检索参数,查询数据库,构建html表单并将其发送给客户端。
You can also go client side with plain javascript or jquery , in which case you will still have to do some server side programming to query the database but will use an ajax call to get the data and will populate the fields in Javascript or JQuery. 您也可以使用普通的javascript或jquery进入客户端,在这种情况下,您仍然必须进行一些服务器端编程来查询数据库,但是将使用ajax调用来获取数据并填充Javascript或JQuery中的字段。
You can do this using Javscript(using Ajax) 您可以使用Javscript(使用Ajax)来执行此操作
Google for jquery ajax examples, and how to populate input using javascript. Google for jquery ajax示例,以及如何使用javascript填充输入。
There are many frameworks out there that have DataBinding built-in that do the same job a lot easier. 那里有许多内置了DataBinding的框架,它们可以轻松完成相同的工作。 My favourite would be Angular Js, you can try Ember and lot more out there, choose the one you feel comfortable with.
我最喜欢的是Angular Js,您可以尝试Ember并在那里找到更多选择,选择一个自己喜欢的产品。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.