redirect if variable=x

He has: 688 posts

Joined: Feb 2001

Hi all. Hope this is an easy one for you PHP'ers. I've got a directory of people that displays 'where they are now' according to their unique "id" field. In other words, file.php?id=151 will call up somebody's personal info from a mySQL database. Well my situation is that one person sadly died. I made a tribute page. I don't want to remove their listing in the directory because somebody may be looking for info on him. What I want to do is redirect them to the tribute page instead of the database query page as everybody else would be listed. In short what I want to do is say if $id=21 then redirect to tribute.php. If this can't be done in PHP then I'll take any other solutions.

Thanks.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I would recommend altering the database. You're only going to have more people die. And I don't think you want to be editing old files everytime this happens.

Perhaps add a short varchar(30) field which contains the name of a file. Default value is an empty string. If the person dies, change the value of the field to the name of a file.

Example: John Doe died... create an 'In Honor Of" page, and call it "john_doe.php" and save it in a directory.

Now, anytime you query the DB for anyone, check this field first. If the field is empty, pull up records as usual. If the field is not empty, redirect to your directory/file_name.php.

redirect:
header("Location: http://example.com/path/to/file.php");

The path may be absolute, relative, or a full URL.

Mark Hensler
If there is no answer on Google, then there is no question.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Alternatively, add one field to the main database and an additional table.

Main Database: Date of Death

New Table: id, Obituary (blob?)

Then, if there is a Date of Death, display it and a link to the obituary so that if people only want the information, it's available, otherwise they can view the obituary.

Under the same set up, you can also display the obituary at the top of the information without offering the choice.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.