Hello,
I make site for sport statistic with Dreamweaver. I have problem only with head-to-head section and need ideas and help.
I have two InnoDB tables:
1. player - info for every player (player_id, player, dob, country....) and
2. matches - results from matches between players (matches_id, player1, score, player2, score2, season.......)
I made two dynamic List Menues and Go buton linked in detailed page with matches between selected player. First I tried to pass with URL parameter and with Form Variable, but no result. Now I'm thinking to make relations between two tables, but it is so complicated. In table 'players' I have name of every player in table 'matches' I have two columns with names of players? I need ideas and help how to make this complex for me query, please?
Hey.
We need to see the code to be able to help. (Not all of it, but the relevant parts.)
In general, you just need a <form> with two <select> boxes - one for each player - populated by fetching the player details from MySQL. Then, once two players are selected from the <select> boxes, the IDs of those players are sent to the action page, which reads them and fetches the record from the database.
6 1648 Atli 5,058
Expert 4TB
Hey.
We need to see the code to be able to help. (Not all of it, but the relevant parts.)
In general, you just need a <form> with two <select> boxes - one for each player - populated by fetching the player details from MySQL. Then, once two players are selected from the <select> boxes, the IDs of those players are sent to the action page, which reads them and fetches the record from the database.
That is good idea. Thank you!
Is that mean, that I must have two foreign keys in table 'matches' with players_id from table 'players'? Or I can use players names for foreign keys?
Atli 5,058
Expert 4TB
In a situation like that the best method would be to use a many-to-many (N:M) relationship.
One of the basic rules of database design is to never put more than one column into a table to hold the same type of value. - For example, in your table you would have to put two columns for players. Those two columns would be identical, except for the name - Now imagine if, in the future, you needed to have more than two players for a match... what would you do then? You would have to modify the table to add more player columns.
That is what a N:M relationship is meant to prevent. You basically pull the player columns out of the match table and create a intermediary table that holds a reference to a single player and a single match. That way you can add as many players as you need to any one match.
This is what a typical N:M relationship would look like: - +---------+ +--------------------+ +--------------+
-
| players | | player_match | | matches |
-
+---------+ +--------------------+ +--------------+
-
| id (PK) |>--->| player_id (PK, FK) | <| id (PK) |
-
| name | | match_id (PK, FK) |<-/ | description |
-
| etc.. | | player_score | | or_something |
-
+---------+ +--------------------+ +--------------+
To use this effectively, you would need to use joins. (Lots of tutorials on that available via Google.) I won't go into to much detail on that, but here is an example of what those look like. This query would fetch all the players for a given match from the above tables: - SELECT
-
m.id,
-
m.description,
-
p.name AS 'player_name',
-
pm.score
-
FROM matches AS m
-
LEFT JOIN player_match AS pm
-
ON pm.match_id = m.id
-
LEFT JOIN players AS p
-
ON p.id = pm.player_id
-
WHERE m.id = 1;
This basically "joins" the tables so that we can query them as a single table. Makes it possible to filter and return data from multiple tables in a single query.
Perfect! I will try that! Thank you very much!
Hi,
Finaly I make query! Your help was great. Now I have other problem. I'm trying to pass 2 parameters from 2 drob down menus (player names) and don't know how to connect thouse 2 parameters with query in detailed page? I have two variables: $pl1 and $pl2 from drob down menus from master page. In detailed page I have folowing SELECT: - SELECT m.name,m.name2,score,score2
-
FROM matches_db m JOIN players_db a ON m.name=a.name JOIN players_db b ON m.name2=b.name
-
WHERE m.name IN ($pr1,$pr2) AND m.name2 IN ($pr1,$pr2)
may be somwhere I must have POST or GET to get thouse two variables from master page? Help, please!
Atli 5,058
Expert 4TB
Hey.
So the problem is getting the variables from the <select> boxes into the query on the detail page?
This is how something like that usually goes: - <!-- In master page -->
-
<form action="details.php" method="post">
-
<select name="player1">
-
<option value="1">First</option>
-
<option value="2">Second</option>
-
</select>
-
<select name="player2">
-
<option value="1">First</option>
-
<option value="2">Second</option>
-
</select>
-
</form>
- <?php
-
// In details page.
-
if(isset($_POST['player1'], $_POST['player2']))
-
{
-
$player1 = mysql_real_escape_string($_POST['player1']);
-
$player2 = mysql_real_escape_string($_POST['player2']);
-
-
$sql = "SELECT stuff
-
FROM table
-
WHERE player1='{$player1}'
-
AND player2='{$player2}'";
-
-
$result = mysql_query($sql) or trigger_error(mysql_error(), E_USER_ERROR);
-
-
// Then display the results.
-
}
-
?>
Always remember the mysql_real_escape_string function when using input data in a MySQL query! Arguably one of the - if not "the" - most important thing we learn about PHP. (See SQL Injection for details on that.) Sign in to post your reply or Sign up for a free account.
Similar topics
by: Starbuck |
last post by:
OK, first let me say that I am no DB person.
But I have a user here who keeps getting this error
whenever she does, whatever it is she does, with
databases...
A google search takes me to...
|
by: Eva |
last post by:
Hi,
Im new to Vb.net and am trying to create my first
practice project. The problem iv encountered is to do
with SQL queries issued against my Access DB iv created.
i want to wright a query...
|
by: |
last post by:
having a spot of trouble writing this one. if you are so inclined and have a
moment, i'd really appreciate your insight.
i have what amounts to a purchase order type of setup...a descriptive...
|
by: John Baker |
last post by:
Hi:
As those who have looked at this newsgroup recently will realize, I am a neophyte with
Access, although I have experienced with Approach (the Lotus product). There are things I
could easily...
|
by: Melissa Kay Beeline |
last post by:
OK, here's the sitch : we have an access control system at work that
registers ever entry/exit of every employee. I recently made some
queries in Access so the ppl in HR could make reports (who...
|
by: dd_bdlm |
last post by:
Please help this one is driving me mad! I have searched and read all
the topics on the error message I am receiving but none seem to apply
to me!
I have quite a complex query linking all parts...
|
by: babyangel43 |
last post by:
Hello, I have a query set up in Access. I run it monthly, changing
"date of test". I would like this query to be merged with a Word
document so that the cover letter is created in Word, the fields...
|
by: Justin |
last post by:
Here's my XML:
<?xml version="1.0" ?>
<AppMode Type="Network">
<CurrentFolder Path="c:\tabs">
<Tabs>
<FilePath>tabs\Justin.tab</FilePath>
<FilePath>tabs\Julie.tab</FilePath>
*****There could...
|
by: crystal2005 |
last post by:
Hi,
I am having trouble with some complex SQL queries. I’ve got winestore database, taken from Web Database Application with PHP and MySQL book. And some question about queries as the following
...
|
by: william67 |
last post by:
I'm having a hard time building a query to do what I need to do and was hoping some genius could help me out, I need to do a complex query and any and all help is much appreciated
this is the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |