virtuex7
12-06-2004, 03:17 PM
How would I go about setting this kind of system up? Where instead of each fighter having his own .php page (ex : golyav.php (by last names)), how can I do what Sherdog.com does :
http://www.sherdog.com/fightfinder/fightfinder.asp?fighterid=4416
and assign them to numbers, etc.
David
12-07-2004, 03:24 AM
Finally a PHP question that I can answer haha.
OK, first you have your usual layout (header, main content, footer), now where you want the switched content to be (main content) put this:
<?php
switch( $HTTP_GET_VARS['id'] ) {
case 'case1':
include("case1.php");
break;
case 'case2':
include("case2.php");
break;
case 'case3':
include("case3.php");
break;
} ?>
Your urls would be index.php?id=case1, index.php?id=case2 etc etc etc for however many you add.
If you want them numbered, just change case1, case 2 etc to a number then change your links to index.php?id=1 or whatever you have set in your includes. Or if you want to change id to something else such as ?article= just change 'id' to 'article' in the PHP.
If this doesn't make much sense, I can explain further.
virtuex7
12-07-2004, 11:07 AM
Ok, so how would I go about doing this
Fighters Name as a link, ex : Travis Wiuff (as a link to his ID # / page)
after they click the fighter it goes to his personal stats page.
Arch Stanton
12-07-2004, 11:20 AM
If you are going to what David suggests, you would be better off to just link to those individual pages. Search engines don't like query strings, so avoid them when you can. Users don't like them either. Here is a post that has some info to get around query strings:
http://www.steeldolphin-forums.com/showthread.php?t=741
What sites that use these methods are doing, id grabbing the ID and retrieving associated information out of a data base with it.
Let's say you have a mysql database named `emfc` table named `fighters` with the fields `id`, `name`, `description` and you are accessing the page with a URL like this:
http://mysite.com/fighter.php?id=23
First you have to connect to the database server and slect the database you want to use:
$db_host = "localhost";
$db_username = "emfc_user";
$db_password = "emfc1234";
$db_name = "emfc";
mysql_connect("$db_host", "$db_user", "$db_pass");
mysql_select_db("$db_name");
Usually thats done with a function in a global include file.
Then you need retrieve the information from the table using the ID passed on from the query string.
// $_GET[id] is the value of 'id' retrieved from the query string
$sql="SELECT * FROM `fighters` WHERE id='$_GET[id]';";
$query=mysql_query($sql);
$array=mysql_fetch_array($query);
Now we need to display the information we retrieved.
echo "<h1>$array[name]</h1>";
echo "<p>$array[description]</p>";
This just simply covers retrieveing information from the database, you still need to create the database and fill it with information first, and there are whole books that cover this, so a post in a forum would not come close to covering it.
Many servers that have php and mysql also have phpmyadmin installed on them which makes tasks like creating and updating tables quite a easy. Check to see if your server has it installed. You can download and install it yourself if need be.
David
12-07-2004, 11:26 AM
OK, so say that his ID number is 3 for talking sake and I made up the rest of the fighters and their IDs to make it easier to understand.
Your php would look like this:
<?php
switch( $HTTP_GET_VARS['id'] ) {
case '1':
include("johnsmith.php"); /* <--- file contains your fighter's page*/
break;
case '2':
include("jackforrester.php");
break;
case '3':
include("traviswiuff.php");
break;
} ?>
You would link to him using the following:
<a href="yourpage.php?id=3>Travis Wiuff</a>
Obviously yourpage.php would be the page where you have the includes code.
I'm not the most helpful when it comes to explaining things, so maybe someone else could explain better than me.
But I hope this somehwhat useful :)
See someone beat me too it heh.
Jeff O.
12-07-2004, 11:29 AM
Many servers that have php and mysql also have phpmyadmin installed on them which makes tasks like creating and updating tables quite a easy. Check to see if your server has it installed. You can download and install it yourself if need be.
I've used a db admin tool called SQLyog for the last year or so and it's pretty nice, for free anyway. You can download it HERE (http://www.webyog.com/index.php). Best of luck. :)
virtuex7
12-07-2004, 12:51 PM
Mmmm. David, thanks alot man, shit works great. I love PHP now. Screw HTML.. I used HTML for like 2 years until now.
:).