简体   繁体   English

如何根据页面URL在数据库中填充页面上的表单字段?

[英]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. 我提供了一个简单的图表来细分我要尝试执行的操作。

http://i.stack.imgur.com/ezMBm.png

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 , in which case you retrieve the parameter, query the database, build the html form and send it to the client. 然后,您必须选择是否要使用类的语言在服务器端构建页面,在这种情况下,您需要检索参数,查询数据库,构建html表单并将其发送给客户端。

You can also go client side with plain or , 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. 您也可以使用普通的进入客户端,在这种情况下,您仍然必须进行一些服务器端编程来查询数据库,但是将使用ajax调用来获取数据并填充Javascript或JQuery中的字段。

You can do this using Javscript(using Ajax) 您可以使用Javscript(使用Ajax)来执行此操作

  1. U need the key to search for get the results from database 您需要密钥来从数据库中搜索结果
  2. Using ajax call get the data, You might have to write code to get the details from database using any server side prog language 使用ajax调用获取数据,您可能必须编写代码以使用任何服务器端编程语言从数据库获取详细信息
  3. Using javascript to fill the form input with the received data. 使用javascript将接收到的数据填充到表单输入中。

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.

相关问题 如何从MySQL数据库中提取数据以在页面加载时预先填充表单? - How do I pull data from my MySQL database to pre populate a form on page load? 如何使用jQuery从同一页面上的数据库记录填充表单 - How to use jquery to populate a form from database record on the same page 如何“发布”到页面并填充表单数据? - How do I 'POST' to a page and populate the Form Data? 如何遍历页面上的表单域并将其发送到数据库? - How do I iterate through form-fields on a page and send them to a database? 使用页面URL填充表单字段 - Populate a form field with page URL 如何将第1页的输入字段传递给第2页的隐藏字段,然后在javascript中显示第2页到第3页的隐藏字段? - How do I pass input fields from page 1 to hidden fields on page 2 and then display hidden fields from page 2 to page 3 in javascript? 如何根据从其他页面点击的链接填充页面内容? - How to populate page content based on link clicked from another page? 如何基于表单数据重定向到页面? - How do I redirect to a page based on form data? 如何在 ReactJS 中将表单字段从一页传递到另一页? - How to pass form fields from one page to another page in ReactJS? 如何根据iframe的网址是否更改来更改父页面的网址? - How do I change parent page url based on if url of iframe is changed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM