Jump to content

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


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.

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.