简体   繁体   English

如何使用jquery或php在MySql数据库中显示链接

[英]How to display a link from the MySql database in html using jquery or php

I have cascading drop down form with 3 fields and 'Submit' button. 我有3个字段和“提交”按钮的级联下拉表单。 Every field responds to each table in MySQL. 每个字段都响应MySQL中的每个表。 So, if you choose an option from each drop down field and hit the 'Submit' button, the script returns and display an info of selected options. 因此,如果您从每个下拉字段中选择一个选项并点击“提交”按钮,则脚本将返回并显示所选选项的信息。 See an example: http://blueicestudios.com/chained-select-boxes/three-tier/ What I'm trying to do, is when every options are selected and the 'Submit' button is hit the link to the specific page should also displayed with an info of chosen option. 参见示例: http : //blueicestudios.com/chained-select-boxes/three-tier/我想要做的是选择每个选项并单击“提交”按钮时,链接到特定页面还应显示所选选项的信息。 From an example: I selected a White Ford Mustang - For this type of selection I have a link to the page with a car in MySQL. 从一个示例中:我选择了白色福特野马-对于这种类型的选择,我具有指向MySQL中带有汽车的页面的链接。 But, I have no clue how to display it on the page. 但是,我不知道如何在页面上显示它。 Any idea how to bring it to alive? 任何想法如何使它活着吗? Thanks 谢谢

Just put the url in the form action: 只需将URL放入表单操作中即可:

$('form').attr('action','hondaCivicRed.php');

Or whatever they chose. 或他们选择的任何东西。

Submit will take them to the url 提交将把他们带到URL

Edit: 编辑:

$('document').on('change','#drop_3',function(){
   var url = $('drop_1').val()+$('drop_2').val()+$('drop_3').val()+'.php';
   $('form').attr('action',url);
});

It is actually quite a long answer to this question and too much code to write but here is the logic. 实际上,这个问题的答案很长,需要编写太多代码,但这是逻辑。

There are MUCH better ways of doing this (tables with JOINS etc.) but as a basic 'get it going' you just need to do the following (assuming you have worked out how to post the data and get the $_POST data back) 有很多更好的方法(带有JOINS的表等),但是作为基本的“入门”,您只需要执行以下操作(假设您已经确定了如何发布数据并获取$_POST数据)

You could then set a table like so: 然后可以像这样设置一个表:

Manufacturer, Model, Colour, URL

Then just query the database with SELECT URL FROM table WHERE manufacturer=$_POST['manufactuer'] AND ..... 然后只需使用SELECT URL FROM table WHERE manufacturer=$_POST['manufactuer'] AND查询数据库SELECT URL FROM table WHERE manufacturer=$_POST['manufactuer'] AND .....

(obviously the above is pseudo code but gives you the logic) (显然以上是伪代码,但给了您逻辑)

header('Location: $url); in your php. 在你的PHP。

Hope the above gives you an idea 希望以上内容能给您一个想法

The better way would be to dynamically create the pages from the database (so you dont need to create a new page for each colour, model etc.) but should give you a grounding 更好的方法是从数据库中动态创建页面(因此您无需为每种颜色,型号等创建新页面),但应该为您提供基础

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

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