View Full Version : Is it possible to have multible fields in a field?
XtremeGamer99
08-06-2004, 03:19 AM
Okay, I am probably going to confuss you guys on this, but here it goes:
I am making a gaming site that is PHP/MySQL drivin.I put all the codes, games, basically any informaton in the database, and use PHP to take it out. Well, I've been workking on this little project for about a week now, and it just dawned on me. If I can only get one cheat code in per field, how am I going to add multiple cheats. I use one row for easch game title that I am going to use for my site, so, that means that if I wanted cheat codes, I would have one colomn for each cheat. But I can't do that, because I want to type in one code for the "code page" (where the cheats are viewable after the user clicks on the the game title), so that all the codes show up. I guess it would be better to show rather than tell:
http://free.hostultra.com/~XtremeGamer99/mysql.html
Each one of those Hi's, Hi there's, Me's, and Today's is a separate row (sopposed to be), so when I call for Madden NFL 2002, it diplays all of that, in separate sections of the page. I hope you know what i am talking about, because I am sorry to say that I do not have any kind of "real" example online. Thanks for any help.
hemebond
08-06-2004, 08:39 AM
Remove the cheat field from the table; create a new table with 2 columns. One column for the game name (from the first table), and the other column for the cheat; then use SQL to join the 2 tables.
XtremeGamer99
08-06-2004, 02:18 PM
Remove the cheat field from the table; create a new table with 2 columns. One column for the game name (from the first table), and the other column for the cheat; then use SQL to join the 2 tables.
But I don't want a separate table for each game. Also, how do you join them, and what does joining them do? And besides, it's not just the cheats that need to be separate for multiple fields, it also is author, date, and probably alot more once I think of them. Can somebody please explain in full, (english please)detail on how do do this?
Thanks.
you best readup on relational designs and database normalisation.
The way it works, is that you group all describing attributes that logically belong together, in a table. And that you then use the primarykey from that table inside a so called 'factstable'.
For example, in your situation, you would have a table like
games --> containing the columns gameID, gamelongname, gameshortname, producer, releasyear, ... (possible other data about the game
The gameID is an autonum column that you created a primary key(PK) on.
You then do the same for authers (columns autherID, authername, joindate, email etc) and cheats (cheatID, cheattitle, cheattext, creationdate).
Now, if 1 cheat can only be used inside one game (you need to be absolutely shure about that !!) then you could also include gameID inside the cheat-table. If every cheat only has one auther, then you can also add autherID to the cheattable.
So imagine gameX has gameID=5 and autherX has autherID=88.
If autherX writes a cheat for gamaX, then there will be a record in the cheat-table like
cheatID |cheattitle|cheattext|createdate|auther|game
787999 | blablabla|bbbbbbbb|2004-01-01| 88 | 5
The big advantage is that you only store the data about that game and auther at one place, and only once. You could change the gamename or authername, without that it would affect your cheatinfo.
You can now get the info you need by joining the tables on their mutual fields. (cheats can be joined with authers on the auther-autherID relationship. and cheats can also be joined with games on the game-gameID relationship)
Like
SELECT games.gamelongname, games.gameshortname, authers.authername, cheats.cheattitle, cheats.cheattext FROM (cheats INNER JOIN games ON cheats.game=games.gameID) INNER JOIN authers ON cheats.auther=authers.autherID WHERE cheats.game =10
which would give you all the cheats for the game with PK=10, and by joining tothe games and authertable, you can then display the data you need from each table.
XtremeGamer99
08-06-2004, 04:15 PM
So, your saying to do something like this:
Games Table:
+-------+----------+-----------+
|game_id|long_name|short_name|
+-------+----------+-----------+
Authors Table:
+--------+------------+
|author_id|author_name|
+--------+------------+
Cheats Table:
+--------+----------+----------+-----------+
|cheat_id|cheat_title|cheat_text|cheat_date |
+--------+----------+----------+-----------+
And then, have it all connect? But, I am not using a single page for each game. I'm trying to surpress the work I have to do by not adding a single page to each game I have by having a url like this:
index.php?letter=s&game=madden2002
So that means that this whole script is in one singe file. So, I can have an individual page for each game. If that were the case, I could probably do the above, since I am targeting that one game. But, since it in o0ne big script, I don't think I can do that. And if I could do that, then there would be a lot of coding invovled, I'm sure, because i have to really know what I'm doing to not get 50+1 error on the screen. And I am a rookie PHP coder, so I'm not sure how I would be able to do it.
I am terribly sorry if that didn't make any sence, but it's hard for me to explain stuff. That's why everyone gets an F on their test after I try to teach them whatever we are larning. =)
you obviously don't understand how a relational designand a databasedrive application works.
if you use the design that i outlined above (adding the auther and market keys to the cheatstable) then you could get all cheats for a specific game like this
//assuming the url to this page was test.php?game=10
$sql = "SELECT games.gamelongname, games.gameshortname, authers.authername, cheats.cheattitle, cheats.cheattext FROM (cheats INNER JOIN games ON cheats.game=games.gameID) INNER JOIN authers ON cheats.auther=authers.autherID WHERE cheats.game =" . $_GET['game'];
$result=mysql_query($sql) or die ('queryproblem');
...
This would then dynamically build the page for that game. The very same test.php page would dynamically build a page for game 11, 12 etc if the value in he querystring was different.
XtremeGamer99
08-06-2004, 06:19 PM
Oh. I get it now. But i have just one more question. How do I add the cheats to the database and how do I use this.
The reason why I ask this is because I don't do well with things working together like that (tables connecting to tables), because I get confused. Say someone sends me a cheat. What all do I need to add to the database so that te author shows up with the cheat they submited, and the cheat goes with the proper game. I know it is a stupid question, but i've never before seen a MySQL Query like that, and I'm a bit confused. :confused:
well, server side scripting is an 'all or nothing' kinda game.
you'll need to learn how everything works together but that is a bit beyond the scope of a post like this.
You need to think of the db as a sort of container that holds the info. The webapplication is the screen where you project it on using a server side language (PHP). The webaplication is in most cases also the input-side.
In your case, you'll probably have a page that lists all games --> list is dynamically generated in PHP from the db.
Like
$sql="select gamesID, gamelongname from games order by gamelongname asc";
$result=mysql_query($sql) or die ('Queryproblem');
if (mysql_num_row($result) >= 1){
while ($row=mysql_fetch_assoc($result)){
echo ('<a href="./showcheats.php?game='. $row['gamesID'] .'" title="see all cheats for this game">Cheats for '. $row['gamelongname'] .'</a><br />
<a href="./newcheat.php?game='. $row['gamesID'] .'" title="ad a new cheet for this game">Add cheet to '. $row['gamelongname'] .'</a><br /><br />();
}
} else {
echo 'no games available';
}
so if the user hit the first link of each game, they'll go to a page where you run a query like in my previous post, and thn all cheats are selected and displayed
if they hit the second link, then you open a form where they can enter the cheats name, description etc.
You already heve the game (you grab it from the querystring with $_GET['game']) and normally, the user will have logged in, so you also have the autherID in a sessionvariable or cookie.
When they submit the form, you just make an insert into the cheats table. Like
$ins="insert into cheats (cheattitle, cheattext, creationdate, game, auther) values ('". $_POST['title'] ."','". $_POST['descr'] ."',Now(), ". $_POST['game'] .", ". $_SESSION['auther'] .")";
$result=mysql_query($ins) or die ('Queryproblem');
The next time someone requests all cheats, this new one will also be shown. You see? It's just a matter of passing along and storing data.
You'll have a page with a form to insert/edit games data and one to do the same for the authersdata. Just like the cheats-data form. And then it's just a matter of linking everything together.
If you wanna get into this, then check out http://www.hotscripts.com/PHP/Tips_and_Tutorials/index.html for some tutorials on formprocessing, db-interaction etc
XtremeGamer99
08-07-2004, 12:35 AM
EDIT: Nevermind about this post, see next post.
XtremeGamer99
08-07-2004, 05:05 AM
Here is my code for the script. I tweaked it a little bit to make it so that it sorts by letter. I also tweaked it so that the $_GET['game'] it variabled to $game. That's about all that I've done. Oh, and I changed some MySQL Field Names. But, It gives me this error :
Parse error: parse error, unexpected T_STRING in C:\apache2triad\htdocs\index5.php on line 26
Here is the code. Can you (or someone. I don't care who) review it and tell me what is wrong. i can't find anything:
<?php
// Connect to the database server
$connect= @mysql_connect('localhost', 'root', 'DELETED');
if (!$connect) {
die( '
Unable to connect to the database server at this time.
' );
}
// Select the database
if (! @mysql_select_db('gamecube', $connect) ) {
die( '
Unable to locate the cheats database at this time.
' );
}
$letter = $_GET['letter'];
$game = $_GET['game'];
if (isset($game))
{
$sql = "SELECT games.gamename, authers.authername, cheats.cheattitle, cheats.cheattext FROM (cheats INNER JOIN games ON cheats.game=games.gameID) INNER JOIN authers ON cheats.auther=authers.autherID WHERE cheats.game =" . $game;
$result=mysql_query($sql) or die ('queryproblem');
if (mysql_num_row($result) >= 1){
while ($row=mysql_fetch_assoc($result)){
echo ('
Cheat Title: $row['cheattitle']<br>
Cheat Text: $row['cheattext']<br>
');
}
} else {
echo 'No cheats';
}
}
else if (isset($letter))
{
$sql="SELECT gamesID, gamename FROM games ORDER BY gamename asc WHERE gamename LIKE '".$letter."%'"
$result=mysql_query($sql) or die ('Queryproblem');
if (mysql_num_row($result) >= 1){
while ($row=mysql_fetch_assoc($result)){
echo ('
<a href="' . $_SERVER['PHP_SELF'] .'&game='. $row['gameID'] .'">Cheats for '. $row['gamename'] .'</a><br />
');
}
} else {
echo 'no games available';
}
}
else {
echo('
<a href="' . $_SERVER['PHP_SELF'] .'?letter=s">S</a><br>
<a href="' . $_SERVER['PHP_SELF'] .'?letter=b">B</a>
');
}
?>
The MySQL stuff (If it helps):
Authors table:
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| authorID | varchar(255) | | | | |
| authorname | varchar(255) | | | | |
+------------+--------------+------+-----+---------+-------+
+----------+---------------+
| authorID | authorname |
+----------+---------------+
| 1 | XtremeGamer99 |
+----------+---------------+
Cheats Table:
+------------+--------------+------+-----+------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+------------+-------+
| cheatID | varchar(255) | | | | |
| cheattitle | varchar(255) | | | | |
| cheattext | varchar(255) | | | | |
| cheatdate | date | | | 0000-00-00 | |
| auther | varchar(255) | | | | |
| game | varchar(255) | | | | |
+------------+--------------+------+-----+------------+-------+
+---------+------------+-----------------------------------+------------+--------+------+
| cheatID | cheattitle | cheattext | cheatdate | auther | game |
+---------+------------+-----------------------------------+------------+--------+------+
| 1 | Hi there | Hi There. Is this script working? | 2004-08-06 | 1 | 1 |
+---------+------------+-----------------------------------+------------+--------+------+
Games Table:
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| gameID | varchar(255) | | PRI | | |
| gamename | varchar(255) | | | | |
| producer | varchar(255) | | | | |
| genre | varchar(255) | | | | |
| release | varchar(255) | | | | |
+----------+--------------+------+-----+---------+-------+
+--------+----------+----------+-------+---------+
| gameID | gamename | producer | genre | release |
+--------+----------+----------+-------+---------+
| 1 | sonic | N/A | N/A | N/A |
+--------+----------+----------+-------+---------+
I'm thinking that it is because I have two $sql and two $result in the same script, but I changed it and everything that uses it by adding a 2 at the end but it still gives me an error...
Also, one more thing: I just want the authors name to appear in the cheats table, not in a individual table, because all I am going to use with authors is thier names, not e-mail, website, ect. So what do I edit/delete to completly remove the authors table without causing errors? I would do it, but I've allready caused an error adding my own script, so i am afraid to touch it. I hope you can help me out.
You get the error because you included a variable inside a singlequoted string.
echo ('
Cheat Title: $row['cheattitle']<br>
Cheat Text: $row['cheattext']<br>
');
should be
echo ('Cheat Title:' . $row['cheattitle'] . '<br>
Cheat Text:' . $row['cheattext'] . '<br> ');
Some other problems:
// Connect to the database server
$connect= @mysql_connect('localhost', 'root', 'DELETED');
if (!$connect) {
die( '
Unable to connect to the database server at this time.
' );
}
// Select the database
if (! @mysql_select_db('gamecube', $connect) ) {
die( '
Unable to locate the cheats database at this time.
' );
}
can be shortened + should be inside a seperate file (call it sdfsdfsdconnectsdqsd.php or so) thet you then include in each page that requires a connection. This file then needs to look like
<?php
// Connect to the database server
$connect= @mysql_connect('localhost', 'root', 'DELETED') or die ('Unable to connect to the database server at this time.' );
// Select the database
@mysql_select_db('gamecube', $connect) ) or die('Unable to locate the cheats database at this time.' );
?>
You then include it in your page like this
<?php
require ('sdfsdfsdconnectsdqsd.php');
$letter = $_GET['letter'];
...
?>
I just want the authors name to appear in the cheats table, not in a individual table, because all I am going to use with authors is thier names, not e-mail, website, ect. So what do I edit/delete to completly remove the authors table without causing errors?
That is not the way to look at it. Even if you only use the name, you should still store it inside a seperate table. Data should not be repeated (more updatingproblems) and selecting/filtering on an indexed numerical column is waaay faster then selecting/filtering on a stringcolunm.
Relational designs are also much more flexible : even if you now only use the name or only include the name inside you authertable, nothing guarantees that you wount add anything to it later on.
So it's better to leave it as it is.
You however need to change your columntypes
authorID, cheatID, gameID should all be of a numerical type (mediumint for instance), should be the primary key and should be the autonum column.
auther and game inside the cheat table, should be of the same columntype (mediumint) and you should create an index on them.
To make it fully normalised:
producer could probably be included inside the auther-table (best rename the authertable to persons or whatever) or else, you should set up a new table with only the producers and include the PK in your cheatstable as an indexed mediumint-column(just like the auther and game column).
Imagine that the producer changes his name --> this well then only require the update of 1 single field. + your db will be much faster when you use indexed numrical columns to filter on.
genre --> same here. Move to another table and only include the PK of that table here
release --> should probably be a numerical column.
XtremeGamer99
08-07-2004, 04:13 PM
[php]
<?php
require ('sdfsdfsdconnectsdqsd.php');
$letter = $_GET['letter'];
...
?>
No need, this is the only page that will use this particular connection.
But I still get errors:
Parse error: parse error, unexpected T_VARIABLE in C:\apache2triad\htdocs\index5.php on line 29
My new php code:
<?php
// Connect to the database server
$connect= @mysql_connect('localhost', 'root', 'DELETED') or die ('Unable to connect to the database server at this time.' );
// Select the database
@mysql_select_db('gamecube', $connect) or die('Unable to locate the cheats database at this time.' );
$letter = $_GET['letter'];
$game = $_GET['game'];
if (isset($game))
{
$sql = "SELECT games.gamename, authers.authername, cheats.cheattitle, cheats.cheattext FROM (cheats INNER JOIN games ON cheats.game=games.gameID) INNER JOIN authers ON cheats.auther=authers.autherID WHERE cheats.game =" . $game;
$result=mysql_query($sql) or die ('queryproblem');
if (mysql_num_row($result) >= 1){
while ($row = mysql_fetch_assoc($result)){
echo ('Cheat Title:' . $row['cheattitle'] . '<br>
Cheat Text:' . $row['cheattext'] . '<br> ');
}
} else {
echo 'No cheats';
}
}
else if (isset($letter))
{
$sql="SELECT gameID, gamename FROM games ORDER BY gamename asc WHERE gamename LIKE '".$letter."%'"
$result=mysql_query($sql) or die ('Queryproblem');
if (mysql_num_row($result) >= 1){
while ($row=mysql_fetch_assoc($result)){
echo ('
<a href="' . $_SERVER['PHP_SELF'] .'&game='. $row['gameID'] .'">Cheats for '. $row['gamename'] .'</a><br />
');
}
} else {
echo 'no games available';
}
}
else {
echo('
<a href="' . $_SERVER['PHP_SELF'] .'?letter=s">S</a><br>
<a href="' . $_SERVER['PHP_SELF'] .'?letter=b">B</a>
');
}
?>
That is not the way to look at it. Even if you only use the name, you should still store it inside a seperate table. Data should not be repeated (more updatingproblems) and selecting/filtering on an indexed numerical column is waaay faster then selecting/filtering on a stringcolunm.
Relational designs are also much more flexible : even if you now only use the name or only include the name inside you authertable, nothing guarantees that you wount add anything to it later on.
So it's better to leave it as it is.
Okay, you kinda lost me there. I didn't really want the author table because I don't need information on the author. I have phpBB and all the authors information is in its phpbb_users table. I also didn't want it because of the authorID because, even though that is a great way to assign a author to a cheat, I can't remember all the authorIDs and thier corresponding authors. But your right, I might need it in the future, and I could serch for a author with phpMyAdmin to find thier ID. I'll leave it...
You however need to change your columntypes
authorID, cheatID, gameID should all be of a numerical type (mediumint for instance), should be the primary key and should be the autonum column.
auther and game inside the cheat table, should be of the same columntype (mediumint) and you should create an index on them.
To make it fully normalised:
producer could probably be included inside the auther-table (best rename the authertable to persons or whatever) or else, you should set up a new table with only the producers and include the PK in your cheatstable as an indexed mediumint-column(just like the auther and game column).
Imagine that the producer changes his name --> this well then only require the update of 1 single field. + your db will be much faster when you use indexed numrical columns to filter on.
genre --> same here. Move to another table and only include the PK of that table here
release --> should probably be a numerical column.
I've changed authorID, cheatID, gameID to mediumint and they are the primary keys for their tables, but I couldn't see a autonum option, to make it a auto number. I looked in the dropdown box, but couldn't see it.
auther and game inside the cheat table are now mediumint, and they are an index.
As for the producer, I'm going to leave it in the game table, since the producer is the one the produces the game, it is near unheard-of that they will change thier company name unless they sold out. Even if that happened, I'll leave it to whatever it is since that was thier name when they produced it. Same for genre, although I don't know why I'm using it. I was going to use it to index the games title (like by letter, only this is by number) but I'm going to pass for now. And I changed the release to to date since it is a date that it was released. The only problem I had with MySQL is that I could find out how to autonum those colomns
Just to clean everything up, the MySQL tables:
Authors Table:
+------------+----------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------------+------+-----+---------+-------+
| authorID | mediumint(255) | | PRI | 0 | |
| authorname | varchar(255) | | | | |
+------------+----------------+------+-----+---------+-------+
+----------+---------------+
| authorID | authorname |
+----------+---------------+
| 1 | XtremeGamer99 |
+----------+---------------+
Cheats Table:
+------------+----------------+------+-----+------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------------+------+-----+------------+-------+
| cheatID | mediumint(255) | | PRI | 0 | |
| cheattitle | varchar(255) | | | | |
| cheattext | varchar(255) | | | | |
| cheatdate | date | | | 0000-00-00 | |
| auther | mediumint(255) | | MUL | 0 | |
| game | mediumint(255) | | MUL | 0 | |
+------------+----------------+------+-----+------------+-------+
+---------+------------+-----------------------------------+------------+--------+------+
| cheatID | cheattitle | cheattext | cheatdate | auther | game |
+---------+------------+-----------------------------------+------------+--------+------+
| 1 | Hi there | Hi There. Is this script working? | 2004-08-06 | 1 | 1 |
+---------+------------+-----------------------------------+------------+--------+------+
Games Table:
+----------+----------------+------+-----+------------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------------+------+-----+------------+-------+
| gameID | mediumint(255) | | PRI | 0 | |
| gamename | varchar(255) | | | | |
| producer | varchar(255) | | | | |
| genre | varchar(255) | | | | |
| release | date | | | 0000-00-00 | |
+----------+----------------+------+-----+------------+-------+
+--------+----------+----------+-------+---------+
| gameID | gamename | producer | genre | release |
+--------+----------+----------+-------+---------+
| 1 | sonic | N/A | N/A | N/A |
+--------+----------+----------+-------+---------+
Going back to the error, I've searched it and couldn't find anything wrong...
dumpfi
08-07-2004, 04:48 PM
On line 29 you forgot the ; at the end.
I've changed authorID, cheatID, gameID to mediumint and they are the primary keys for their tables, but I couldn't see a autonum option, to make it a auto number. I looked in the dropdown box, but couldn't see it.It is named "auto_increment".
Oh, and all your mediumint fields in the table should have a length of about 5 to 8 max instead of 255. This will speed a search up and you may have up to 99.999 to 99.999.999 records per table which should be enough.
Also you may reduce the length of the varchar fields. I doubt there is a game which name is up to 255 characters long. The same for author names, etc.
dumpfi
XtremeGamer99
08-07-2004, 05:12 PM
On line 29 you forgot the ; at the end.
That worked! thanks you. It just comes to show how blind i really am. =)
It is named "auto_increment".
Oh, and all your mediumint fields in the table should have a length of about 5 to 8 max instead of 255. This will speed a search up and you may have up to 99.999 to 99.999.999 records per table which should be enough.
Also you may reduce the length of the varchar fields. I doubt there is a game which name is up to 255 characters long. The same for author names, etc.
dumpfi
Okay. I didn't know that it was in the "Extra" column. I canged everything, and now th varchar fielids for gamename are 50 and authors are 25.
At least I have the S and B links in the page instead of a error, but when I click it, "Queryproblem". I think I can handle this one, though.
XtremeGamer99
08-07-2004, 07:18 PM
Okay, i got another problem. If I could get this one done, I should be able to go on with life. =)
There is something wrong with the MySQl Query on this line:
$sql = "SELECT games.gamename, games.producer, games.release, games.genre, authors.authorname, cheats.cheattitle, cheats.cheattext, cheats.cheatdate, FROM (cheats INNER JOIN games ON cheats.game=games.gameID) INNER JOIN authors ON cheats.author=authors.authorID WHERE cheats.game =' . $game . '";
$result=mysql_query($sql) or die ('queryproblem');
When I go to index.php, I get two links. S and B. There are no games in the database that begin with B, so when I click S, it gives me a link:
Sonic Adventure DX.
But When I click it, it gives me the query problem in the code above. Since I don't understand the joining part of the query (towards the end) I can't really find what is wrong.
The full PHP Script:
<?php
// Connect to the database server
$connect= @mysql_connect('localhost', 'root', 'DELETED') or die ('Unable to connect to the database server at this time.' );
// Select the database
@mysql_select_db('gamecube', $connect) or die('Unable to locate the cheats database at this time.' );
$letter = $_GET['letter'];
$game = $_GET['game'];
if (isset($game))
{
$sql = "SELECT games.gamename, games.producer, games.release, games.genre, authors.authorname, cheats.cheattitle, cheats.cheattext, cheats.cheatdate, FROM (cheats INNER JOIN games ON cheats.game=games.gameID) INNER JOIN authors ON cheats.author=authors.authorID WHERE cheats.game =' . $game . '";
$result=mysql_query($sql) or die ('queryproblem');
while ($row = mysql_fetch_assoc($result)){
echo ('Cheat Title:' . $row['cheattitle'] . '<br>
Cheat Text:' . $row['cheattext'] . '<br> ');
}
}
else if (isset($letter))
{
$sql="SELECT gameID, gamename FROM games WHERE gamename LIKE '".$letter."%' ORDER BY gamename asc";
$result=mysql_query($sql) or die ('Queryproblem');
while ($row=mysql_fetch_assoc($result)){
echo ('
<a href="' . $_SERVER['PHP_SELF'] .'?letter='. $letter .'&game='. $row['gameID'] .'">Cheats for '. $row['gamename'] .'</a><br />
');
}
}
else {
echo('
<a href="' . $_SERVER['PHP_SELF'] .'?letter=s">S</a><br>
<a href="' . $_SERVER['PHP_SELF'] .'?letter=b">B</a>
');
}
?>
The MySQL Tables:
Authors Tables:
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| authorID | mediumint(8) | | PRI | NULL | auto_increment |
| authorname | varchar(25) | | | | |
+------------+--------------+------+-----+---------+----------------+
+----------+---------------+
| authorID | authorname |
+----------+---------------+
| 2 | XtremeGamer99 |
+----------+---------------+
Cheats Tables:
+------------+--------------+------+-----+------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+------------+----------------+
| cheatID | mediumint(8) | | PRI | NULL | auto_increment |
| cheattitle | varchar(255) | | | | |
| cheattext | varchar(255) | | | | |
| cheatdate | date | | | 0000-00-00 | |
| auther | mediumint(8) | | MUL | 0 | |
| game | mediumint(8) | | MUL | 0 | |
+------------+--------------+------+-----+------------+----------------+
+---------+------------+-----------+------------+--------+------+
| cheatID | cheattitle | cheattext | cheatdate | auther | game |
+---------+------------+-----------+------------+--------+------+
| 2 | Hello? | Hi there. | 2004-08-07 | 2 | 2 |
+---------+------------+-----------+------------+--------+------+
Games Tables:
+----------+--------------+------+-----+------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+------------+----------------+
| gameID | mediumint(8) | | PRI | NULL | auto_increment |
| gamename | varchar(50) | | | | |
| producer | varchar(255) | | | N/A | |
| genre | varchar(255) | | | N/A | |
| release | date | | | 0000-00-00 | |
+----------+--------------+------+-----+------------+----------------+
+--------+--------------------+----------+-------+------------+
| gameID | gamename | producer | genre | release |
+--------+--------------------+----------+-------+------------+
| 2 | Sonic Adventure DX | N/A | N/A | 0000-00-00 |
+--------+--------------------+----------+-------+------------+
I can't find out what is wrong...
dumpfi
08-07-2004, 08:46 PM
There was a comma which shouldn't be there, a wrong field name and the variable was built in wrong.$sql = 'SELECT games.gamename, games.producer, games.release, games.genre, authors.authorname, cheats.cheattitle, cheats.cheattext, cheats.cheatdate FROM cheats INNER JOIN games ON cheats.game=games.gameID INNER JOIN authors ON cheats.auther=authors.authorID WHERE cheats.game = "'.$game.'"';
$result=mysql_query($sql) or die ('queryproblem'); dumpfi
XtremeGamer99
08-07-2004, 09:22 PM
Well, that worked partially.
The Cheat Title and Cheat Text showed up, but then I added author and game, but that doesn't work. It is blank.
if (isset($game))
{
$sql = 'SELECT games.gamename, games.producer, games.release, games.genre, authors.authorname, cheats.cheattitle, cheats.cheattext, cheats.cheatdate FROM cheats INNER JOIN games ON cheats.game=games.gameID INNER JOIN authors ON cheats.author=authors.authorID WHERE cheats.game = "'.$game.'"';
$result=mysql_query($sql) or die ('queryproblem');
while ($row = mysql_fetch_assoc($result)){
echo ('Cheat Title:' . $row['cheattitle'] . '<br>
Cheat Text:' . $row['cheattext'] . '<br>
By:' . $row['author'] . '<br>
Game Title:' . $row['game'] . '<br>');
}
}
EDIT: I spelled author wrong in the cheat table, so I corrected it and the one in the query.
dumpfi
08-07-2004, 10:02 PM
Instead of $row['game'] use $row['gamename'] and instead of $row['author'] use $row['authorname'].
dumpfi
XtremeGamer99
08-07-2004, 10:17 PM
Thanks.
Well, it looks like I'm all set. I don't think i'll have any more problems.
I want to thank everyone who has helped me with this script, especialy raf and dumpfi. Thanks for having patience.
- XtremeG@mer99
XtremeGamer99
08-08-2004, 03:59 PM
I'm sorry to trouble you all agian, but I have one more problem. I added my layout to the otherwise plain page. I figured most of it out, except this one:
if (isset($game))
{
$sql = 'SELECT games.gamename, games.producer, games.release, games.genre, authors.authorname, cheats.cheattitle, cheats.cheattext, cheats.cheatdate FROM cheats INNER JOIN games ON cheats.game=games.gameID INNER JOIN authors ON cheats.author=authors.authorID WHERE cheats.game = "'.$game.'"';
$result=mysql_query($sql) or die ('queryproblem');
while ($row = mysql_fetch_assoc($result)){
echo ('
<table width="100%">
<tr>
<td class="B"><font size="6">' . $row['gamename'] . '</font></td>
</tr>
<!-- Enter your news/content here -->
<tr>
<td class="A">' . $row['cheattitle'] . ' </td>
</tr>
<tr>
<td>' . $row['cheattext'] . '
<br />
<br />
<i>- ' . $row['authorname'] . '</i><br />
<br /></td>
</tr>
</table>
<!-- End of content -->
');
}
}
That echos out the game name, cheat text, cheat name, and author name. But, even though it wchos it, it also reapets it, including the game name. But I don't want the gamename repeated. I also don't want a number of other things repeated, but I haven't put them in yet. Someone help we out?
you just need to copaire the value with the value from the previous row, and and only display it if it changed. For instance, if you only need the name once, then you chack if the name from your current record is differnt for the name in the previous record, and only display it if it is indeed different.
For instance like this
$name='';
while ($row = mysql_fetch_assoc($result)){
if ($name !=$row['gamename'] ){
echo '<td>' . $row['gamename'] . '</td>';
$name = $row['gamename'] ;
}
....
}
XtremeGamer99
08-08-2004, 04:47 PM
Thank you very much. It works.
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.