user3473668
user3473668

Reputation: 3

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. Every field responds to each table in 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. 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. But, I have no clue how to display it on the page. Any idea how to bring it to alive? Thanks

Upvotes: 0

Views: 203

Answers (2)

andrew
andrew

Reputation: 9583

Just put the url in the form action:

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

Or whatever they chose.

Submit will take them to the url

Edit:

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

Upvotes: 3

GrahamTheDev
GrahamTheDev

Reputation: 24825

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)

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.....

(obviously the above is pseudo code but gives you the logic)

header('Location: $url); in your 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

Upvotes: 0

Related Questions