Click to See Complete Forum and Search --> : Fun with switch(){}


Mr Initial Man
07-29-2006, 08:21 PM
Not really a question so much as wanting your opinion on something. I've discovered that the switch function can do very nicely when creating a really simple database. What do you guys think? Below is something that I've done for my main website.

<?php
switch ($story)
{
case "beefbottle":
$title = "Beef in a Bottle";
$rating = "14";
$keywords = "steroids, muscle, family";
break;

case "comforter":
$title = "The Comforter";
$rating = "MA";
$keywords = "suicide";
break;

case "darknight":
$title = "Darkest Night";
$rating = "14";
$keywords = "murder, halloween";
$style = "blockquote{background:#fff;color:#008;margin:20px 60px 20px 60px;}";
break;

case "erintopping":
$title = "Meeting Erin Topping";
$rating = "PG";
$keywords = "fan, fiction, fanfic, Erin, Topping, WTF";
$for = "Erin Topping";
break;

case "josef":
$title = "Josef";
$rating = "PG";
$keywords = "muscle, disability";
$for = "Braford";
$forlink = "download.lavadomefive.com/members/braford/";
$fortitle = "Braford's Gym";
break;

case "mimjd":
$title = "Jack Daniels meets John-David";
$rating = "PG";
$keywords = "fursonas, comedy";
$style = "p.name{font-weight:bolder;}";
break;

case "oldstrong":
$title = "The Old That Is Strong";
$rating = "PG";
$keywords = "age, muscle, family";
break;

case "rainyday":
$title = "Rainy Evening Exercise <em style=\"font-size:90%; display:block\">or</em>Doktor Catlove Can Kiss My Wazoo";
$rating = "PG";
$keywords = "fan, fiction, Albert, Temple, Gene Catlow";
$titlebar = "Rainy Evening Exercise";
$for = "Albert Temple";
$forlink = "www.genecatlow.com";
$fortitle = "Gene Catlow";
break;

case "seduction":
$title = "Seduction";
$rating = "NC-17";
$keywords = "adult, yiff, comedy, sex, seduction, porn";
$style = "p.story{font-style:italic;margin:30px 0 30px 0;}";
break;

case "traditions":
$title = "Traditions";
$rating = "PG";
$keywords = "fighting, wrestling, fan, fiction, fanfic";
$style = "p.big{text-indent:0;font-size:110%;text-align:center;font-weight:bold;margin:10px 0 10px 0;}";
$for = "Lysozyme";
$forlink = "download.lavadomefive.com/members/Lysozyme/";
$fortitle = "Lysozyme's Pad";
break;

case "trevordate":
$title = "A Date with Trevor";
$rating = "14";
$keywords = "fan, fanfic, fan fiction, crossdressing, dating";
$for = "Shane Nelson";
$forlink = "www.shaylathepinkmouse.com";
$fortitle = "Shayla The Pink Mouse";

case "wolf":
$title = "Wolf Hunt";
$rating = "14";
$keywords = "Werewolf, hunting, wolf, vore, death, hunt";

default:
$story = "whoops";
$title = "Whoops!";
$rating = "NR";
}
?>

Pretty nice setup, IMHO, but you're all free to thunder at me for being a blasphemer.

NogDog
07-29-2006, 09:02 PM
The main problem I see is in code maintainability: it's just a lot of code to wade through to find the page data you want to modify. Also, there is nothing forcing you to assign a value (or intentionally not assign a value) for each pseudo-field in a given pseudo-row. Mind you, it should work fine (I've done something similar before when using a database wasn't an option, but by defining a multi-dimension associative array.)

Something to consider would be using a CSV file as your "database". This allows you to increase modularity by keeping the data separate from the processing code, plus you could then use Excel or most any other spreadsheet tool to modify your "database" as needed.

Mr Initial Man
07-30-2006, 12:48 AM
Well, this is only an include. There's several if statements dealing with $for, $forlink, $fortitle, $style, and $titlebar saying "if it's empty, ignore any code that goes with it."

NogDog
07-30-2006, 01:19 AM
Well, this is only an include. There's several if statements dealing with $for, $forlink, $fortitle, $style, and $titlebar saying "if it's empty, ignore any code that goes with it."
Understood -- I'm not saying it won't work, or even that it's not a good idea; just why I wouldn't do it that way. Once you get used to working with databases and the concepts associated with data normalization, other methods are just less...satisfying, I guess.

But you definitely get an "A" for creativity. :)

Mr Initial Man
07-30-2006, 01:29 AM
If a database were an option (and it is, should I ask for one), should I go with it?

netbuddy
07-30-2006, 04:46 PM
You have to check the file permissions for file creation on the server, if all ok and you can easily make and amend files on the rreomte server, you can keep all your data in a flat sheet database aka a text file.