1. MAKE SURE YOUR HOST SUPPORTS PHP. This is usually found in your host's FAQ section. Justhost generally does but I'm unsure about other hosts.
2. If you are planning on going the mysql route, you need to have access to that as well. My host provides me with numerous tools for it through my control panel but I prefer phpmyadmin. I am unsure as to how this works if you sublet from a domain.
3. Realize that this takes a really long time to set up depending on how extensive you want your "automation" to be. I have over 550 dragons, so over 550 rows of data, and over 20 columns each. I am still working on filling it all out.
What I use PHP/MySQL for:
- I have all my dragon information in a database.
- Everything you see on pages such as this one is generated through php using data from my database. What this means is that I wrote the code only once and php brings in the information from my mysql database.
- This allows me to build searches that include any field in my database. (I am still working on how to make it search for combinations of fields.)
- PHP can do calculations, such as heat cycles and clutch sizes as seen on pages such as this one. I categorized each dragon by species "type" according to maturity rate, heat cycle length, and average clutch size. PHP then uses this category to perform a sequence of operations to figure out the year of maturity, subsequent years in heat, as well as randomized clutch sizes and amount of duds. (Unfortunately this changes every time I reload the page - I haven't found a way to make it stick.)
- PHP can also hunt down specific lists from my database, as seen by the preferred mate section on the second example page. For that, I told PHP to find dragons within +/- 1 size value.
If you want to just create a search:
- You either need to make a MySQL database or a variable list in php. What you choose is up to you. I have a lot more experience with the database angle but I can figure out how to do the variable list if you want. Information below focuses on the way to do this with MySQL.
- Name your database something you'll remember. Then name your table something descriptive. Mine are "characters" and "dragon_basics".
- In that database, you need to include all the parameters you want to include in your search. I suggest at least Name, Species, Gender, Colour and Home. You likely want to include bond information in the same row (I have mine in a separate database) and the link to that dragon's stats page. See below for example.
Code: Select all
ID# | DragonName | Species | DragonGender | DragonColour | Origin | BondName | BondSpecies | BondGender | Home | Link
1 | Adharath | Pernese | Female | Doom | ESD | NULL | NULL | NULL | SULA | statspage.html
- You then write the PHP file:
Code: Select all
<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","user","password");
//select which database you want to edit
mysql_select_db("characters");
$var = @$_GET['search'] ;
$trimmed = trim($var);
// this is the important part where you edit in the parameters you want to include in your search. use the EXACT names of the columns otherwise your code will give you an error.
$result = mysql_query("SELECT * FROM dragon_basics WHERE DragonName LIKE '%$trimmed%' OR Species LIKE '%$trimmed%' OR DragonGender LIKE '%$trimmed%' OR DragonColour LIKE '%$trimmed%' OR Origin LIKE '%trimmed%' OR Home LIKE '%$trimmed%' ORDER BY DragonName") or die(mysql_error());
// then you type in your page and table structure/headers; echo pretty much means "be seen"; only include the parameters you have included in your database, you won't be able to display that exact info otherwise
echo "<head><title>Character Database: Search</title><link rel=stylesheet type=text/css href=stylesheet.css><center>";
echo "<table><tr><td>Name</td><td>Species</td><td>Colour</td><td>Gender</td><td>Origin</td><td>Bond Name</td><td>Bond Species</td><td>Bond Gender</td><td>Home</td></tr>";
// then you get to start the fun stuff
// this makes your php get the rows that match your search and repeat the following steps until it runs out of rows
// the curly bracket means "within here"; so the repeated steps must be within curly brackets
while($row = mysql_fetch_array( $result )) {
// then you get to start incorporating data into a theoretical row
// this could all go into a single echo, really, but I like to split it up so I know where errors are more easily
echo "<tr><td>";
echo "<a href={$row['Link']}>{$row['DragonName']</a>";
echo "</td><td>";
echo $row['Species'];
echo "</td><td>";
echo $row['DragonColour'];
echo "</td><td>";
echo $row['Gender'];
// and so on and so forth. the syntax is pretty self explanatory and means "express the value for ['COLUMN'] as found in the current row"
// when you're done with your theoretical row, wrap up your repeat clause
}
// then end your table
echo "</td></tr></table>";
// and that's the end of your php file, save this as search.php
?>
Code: Select all
<b>By Dragon</b><br>
<form name="form" action="search.php" method="get">
<input type="text" name="search">
<input type="submit" name="Submit" value="search">
</form>
Let me know if you implement it and get errors - it's possible that the syntax for the link may cause issues. The most common error is to forget a semi-colon at the end of a phrase. Either way, your file should tell you where the error is (by line number) when you try to run it.
If you want to input something fancy for your unbonded dragons, you can try playing with null values. Null does not mean you just type in "NULL", instead you have to check a box on phpmyadmin to have it be deemed null. Once you do this, you can create an if else clause based on that null as follows:
Code: Select all
if (is_null($row['BondName'])) echo "<td colspan=3>Unbonded</td>";
else echo "<td>{$row['BondName']}</td><td>{$row['BondGender']}</td><td>{$row['BondSpecies']}</td>";
Hopefully that's not too confusing! Let me know if you have any questions.