Jump to content

[ resolved ] Using Hyperlinks with PHP & MySQL Database


phpBeginner06

Recommended Posts

I have; what I am sure is a pretty common question, but I am going to ask any way. Because I have tried different variations of creating this code from other examples I have seen on the internet, but have not got any script I made to work yet.

I want to be able to create a hyperlink like this: [nobbc]"<a href=somepage.php?id=3">Ford</a>[/nobbc] and have it link to database that I have created; then send information from the database back to another php page.

[u]Here is some basic information concerning the way I have database set up:[/u]

The database is named "vehicleList".
The data table is named "details".
There are 7 table columns; the names of each are as follows: "id", "year", "link", "make", "model", "series", "price".
There are also 7 rows in the data table; at this time.

I want to be about to click on a link and pull data out of a row and post it to a php web page. I also am not sure how to post the data to the php web page; I have been reading about $_Get['id'], but I tried to create a script with it; and it would not work. I would post the script I had, but I got frusturated at it and deleted it from existance.

Any help with this would be great - Thanks
Link to comment
Share on other sites

So am I right thinking that you want a list of links that are vehilce manufacturers (ie Ford, Vauxhall, Skoda etc) and when click on one of these it will take you to a page where it will pull all records from details to provde a list of vehilces made by that manufacturer.

Is that right?
Link to comment
Share on other sites

I want to be able to click a link; that will send any information in my database's data table row to another page (echo or print it). This way I do not have to go and create a new webpage for every vehicle. I can just add information to database and give link a id; then when end user clicks the link (ie <a href="somepage.php?id3">Ford</a>); data will be transfered from database to a php page, where it will be echoed or printed.

I do not have the specific code I made; I borrowed it from another example online, but never could get it to work for me. I will see if I can find the example and post it back on here.
Link to comment
Share on other sites

Here is an example of the PHP code (aka "somepage.php") I pieced together:

[code]<?

//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("mysql","username","password");

//select database
mysql_select_db("vehicleList");

$id = $_GET['id'];
$search = "SELECT * FROM details WHERE id = '$id'";
$result = mysql_query($search);

while ($row = mysql_fetch_array($result)) {
echo $row["year make model series price"];
}

?>[/code]

Then here would be the HTML hyperlink:

[code]<a href="somepage.php?id=3">Ford</a>[/code]

I have been placing the above link in a web page with a HTML extention. Is that OK or do I have to have a link like this in a web page with a PHP extention, in order for it to function?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.