Jump to content

How to run different sql queries with hyperlinks connecting to a mysql database


Agreaves

Recommended Posts

Let's say you have a URL like:

 

www.example.com/index.php?cat=news

 

In your PHP you'd need to check if:

 

1. 'cat' is present in the URL

2. that it's set to a value you'd accept

 

If so, then load that data:

 

$cat = strtolower($_GET['cat']);

switch ($cat) {
    case "news":
        // SQL to retrieve news from the db
        break;

    // other cases based on whatever you need 

    default:
        // normal home page
}

 

Keep in mind, that's just one way to do it, and it doesn't take security into account.  Without knowing exactly what you want to do, I can't give a better answer.

Lets say I have a link to take the customer to a particular called "Ashtrays", whenever they click the link I want it to run a specific query based on ashtrays and output Picture and description of all the ashtrays in the database. However the respose you gave earlier did give me some ideas. Thank you. I hope this information was more specific.

Archived

This topic is now archived and is closed to further replies.

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