Welcome! Log In Create A New Profile

Advanced

Team_Selection Page

Posted by ginosimon 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
avatar Team_Selection Page
May 08, 2013 01:42PM
Hello,

I am 90% done with my Portfolio but I have hit a roadblock of note with the Selections Page. I am not sure how to bring the fixture_id into play with the selection_id so that i can not only query the database and display all players and fixtures but also use radio buttons and check boxes to select a fixture and then select players for that fixture nad post that back to the database so that all the relevant tables are updated. When the user clicks on the any of the fixtures in my fixtures_public page, the link just goes to a script that queries that database and displays all the players sitting in the players table. I did create a page with checkboxes and then manually wrote in the players names, in the value field of the form, I did something similair to this
Language: PHP
<input type = "checkbox" name = "players" value = "<?php $player_id ?>;">
I just seem to be going around in circles. I would really appreciate any advice or guidance as to how I can go about completing the Selections Page. Thank you.

"It is not the will to win, but the will to prepare to win that makes the difference."
avatar
Mac
Re: Team_Selection Page
May 08, 2013 03:08PM
You can send the fixture_id to your selection page and include it there in a hidden form element, to be sent together with the selections made to the insert page.
avatar Re: Team_Selection Page
May 08, 2013 04:25PM
Thank you Mac. Will try this as soon as I get home.

"It is not the will to win, but the will to prepare to win that makes the difference."
avatar Re: Team_Selection Page
May 08, 2013 11:18PM
Hello Everyone,

I have made progress and I am now able to draw player information (name and surname) as well as fixture information (opponents, date, venue) into the Selection Page. I use the radio buttons to select the fixture and checkboxes to select the players. I have tested and I am able to successfully post the player_id as well as the fixture_id. Everything else in my portfolio works, all I seem to be struggling with is bringing the third table which is for team selections into play. I have set up this table with a selection_id, fixture_id and the positions that are required for my team but I am unable to assign a player_id to any of the positions created in the selections table. Has anyone else encountered similar problems with the Selection Page? I would really appreciate it if I could discuss this with fellow students that are experiencing the same issues. Perhaps I just need a different perspective.

"It is not the will to win, but the will to prepare to win that makes the difference."
avatar Re: Team_Selection Page
May 13, 2013 09:03AM
Hello All,

I have made some progress with my Portfolio and I am almost done except for one issue. I have a team_selection page which allows the coach to select a game using radio buttons and the players using checkboxes.
Language: PHP
echo "<tr><td>$fname</td><td>$sname</td><td><input type = ';checkbox'; name = ';players[]'; value = $player_id</td></tr>"; echo "<tr><td>$opponents</td><td>$date</td><td>$venue</td><td><input type = ';radio'; name = ';fixtures[]'; value = $fixture_id</td></tr>";
With the code above, I am able to post the values to a page called select.php where the player_id's and fixture_id selected is displayed in a table. My problem is that I do not know how to extract the values of the array to then use in my SQL statement. I use the following code to display the player_id's in the table in select.php when the coach presses the Submit button.
Language: PHP
$players = $_POST[';players';]; $n = count ($players); for ($i = 0; $i < $n; $i++) { echo "<tr><td>$players[$i]</td></tr><br>";

The closest I have come to getting the SQL statement has been inserting 1 player for one fixture 11 times, that is, BATSMAN, BOWLER, ALLROUNDER, etc is populated by the last player_id. Any advice will be most appreciated.

"It is not the will to win, but the will to prepare to win that makes the difference."
Re: Team_Selection Page
May 13, 2013 09:26AM
this was answered in the thread:

by "42893275-P"
the thread was called
"Radio / Checkboxes for MySQL "

also referred you to the following page:
http://www.phpfreaks.com/tutorial/working-with-checkboxes-and-a-database
avatar Re: Team_Selection Page
May 13, 2013 09:43AM
Thank you but I have looked at this. I am still uncertain as to how I can extract the player_id's as an array, then assign them to variables and use those variables to update my Selections table based on the fixture_id posted.

"It is not the will to win, but the will to prepare to win that makes the difference."
Re: Team_Selection Page
May 13, 2013 10:03AM
Then i might not be clear as to what you are asking... so lets try this..
http://www.html-form-guide.com/php-form/php-form-checkbox.html
http://www.phpfreaks.com/tutorial/working-with-checkboxes-and-a-database
I am still uncertain as to how I can extract the player_id's as an array,
well the above shows how to get an array... so you just have to send the id's to this array. (can you do this?) so you say you have read it so my guess would be you know how to do it and your problem is else where.

then assign them to variables and use those variables
well, if you have this in an array, then any of the previous Dev subjects... C++ JavaScript the current php will show you have to assign a value to a variable,
and you could just run it through a loop (however, it is in an array, so no need to assign to another variable, would be waste of time and memory, just use the current array in your SQL)

to update my Selections table based on the fixture_id posted.
well there is multiple way's to do this.... and depending on how you structured the table
this answer would be different and I believe that this is why more detail was not given for this, it is meant to test how you figure it out and solve the problem

this should also be pretty basic SQL from last years course....
use your where clause

where are you getting stuck?
do you have ID's in array?
can you not use the ID (or array) in you sql?
can you not find or create the fixture id in the selections table?
avatar Re: Team_Selection Page
May 13, 2013 10:34AM
Hello,

Thank you for your response and feedback. The following code allows me to extract the player_id of each player whose checkbox is checked.
Language: PHP
Language: PHP$players = $_POST[';players';]; $n = count ($players); for ($i = 0; $i < $n; $i++) { echo "<tr><td>$players[$i]</td></tr><br>";
My problem is that when I use $player[$i] outside the table, I can only access the last player checked. So my SQL statement does not update each position in selection_table, BATSMAN, BOWLER, ALLROUNDER, WICKETKEEPER, etc even though I am able to display in a table prior to running the UPDATE statement, the player_id's for each of these positions.:
Language: PHP
query = "UPDATE selection_table SET batsman1 = ';$players[$i]';, batsman2 = ';$players[$i]';,...WHERE fixture_id = ';$fixtures';";

"It is not the will to win, but the will to prepare to win that makes the difference."
Re: Team_Selection Page
May 13, 2013 10:54AM
ok so you say that the loop displays the players correctly in a table?
all of them, but when you do the SQL querry it does not work

I would start by echoing all of your array items and the $fixtures
then going to sql and do the querry there, see if it is not the querry that is wrong?
but from what you are saying I cannot see the prob
avatar Re: Team_Selection Page
May 13, 2013 12:17PM
Yes, the loop displays the players correctly in the table but I am having a problem sending those player_id's to the SQL statement for each position in the selection table. All I have is
Language: PHP
$players[$i]
once the loop has ended and I am not sure if I tried assigning each iteration of the loop to a variable and then using those variables in my SQL statement like so:
Language: PHP
$players = $_POST[';players';]; $n = count ($players); for ($i = 0; $i < $n; $i++) { $bat1 = $players[$i]; $bat2 = $players[$i]; //etc...... } //SQL statement... query = "UPDATE selection_table SET batsman1 = ';$bat1';, batsman2 = ';$bat2';,...WHERE fixture_id = ';$fixtures';";

Thank you 42609852. Just going through this with you has made me consider a few other options. I will do my research at work today and then attempt to complete this when I get home. Thank you.

"It is not the will to win, but the will to prepare to win that makes the difference."
Re: Team_Selection Page
May 13, 2013 02:18PM
No prob, we are here to help eachother...

there it is...
Language: PHP
for ($i = 0; $i < $n; $i++) { $bat1 = $players[$i]; $bat2 = $players[$i]; //etc...... }

this will never work
because when $i = 10
then
Language: PHP
$bat1 = $players[10]; $bat2 = $players[10]; ........ $bat10 = $players[10]; $bat11 = $players[10];


so if $players[10]; = Jacques Kallis
then $bat1 through $bat11 will all be Kallis

why not do this:
Language: PHP
query = "UPDATE selection_table SET batsman1 = ';$players[0]';, batsman2 = ';$players[1]';,...WHERE fixture_id = ';$fixtures';";

and forget the loop? why create more variables if you already have all the values you need in an array (essentially a list of variable's)
(this uses more memory then you need)

also sorry, this took so long
my table looks a little different then this so my code and SQL was a little different (I had to use a loop)

FYI a good way to track that error would have been to place an echo inside of your loop to test the value of the variables and the array items
avatar Re: Team_Selection Page
May 13, 2013 03:00PM
42609852, God Bless you, I am going to definitely go home and give your suggestion a try. And yes, you are correct because I did try something similair and players 1 to 11 were all updated with just the last player_id, no matter what the position in the selection_table. So if I understand you correctly, you are saying drop the for loop since I have proved that I am able to POST the players[] array successfully and use the values of $players[0], $players[1], etc directly in my SQL statement?. All I would have to ensure before the SQL statement is run is that I had the values of players[] and I could get those with:
Language: PHP
$players = $_POST[';players';];
and then use them in the SQL statement as you have suggested.
Strangely enough Jacques Kallis is in my table of players smile I really appreciate the time that you have taken to give me your input and advice. I will definitely let you know how this goes. If I get this right then, I can upload my Portfolio and submit it on time. Thank you once again. Much appreciated.

"It is not the will to win, but the will to prepare to win that makes the difference."
avatar Re: Team_Selection Page
May 13, 2013 08:33PM
42609852 I managed to get it working but I could have never done it without your help. Thank you. thumbs up Now to just tidy up my code and upload. Thank you to everyone else, including you Mac that also contributed with your input and advice.

"It is not the will to win, but the will to prepare to win that makes the difference."
Re: Team_Selection Page
May 13, 2013 09:21PM
Great news.
no prob, hope you ace it.
was a good proj, steep learning curve for me, but was fun.
avatar Re: Team_Selection Page
May 13, 2013 10:09PM
To my detriment I did 4 subjects this semester but PHP was definitely the most challenging and fun. Good luck to you too 42609852

"It is not the will to win, but the will to prepare to win that makes the difference."
Re: Team_Selection Page
May 19, 2013 01:01PM
Hi guys. I also used radio buttons and checkboxes to make selections... I am able to retrieve selected fixtures and players but unable to post the selection to the third table... saw some people talking about join the two tables. I used two queries one for the fixture and the other for players to display the fixtures with radio buttons and players with checkboxes "I can select both the fixture and players" but unable to post the selection to the third table. did you guys join your queries to create one record?

PLEASE HELP.
Re: Team_Selection Page
May 24, 2013 12:46PM
@42893275-P - hope you got this right already...
but...
I think you need at least 3 tables...
one for the fixtures one for the players.... and then a third...
this 3rd table is a linking table that you use to link your players to the fixtures.....
the design on the table is up to you as there is many way's of doing it, some better then others (but as this is not a database module don't think it matters too much)
But MUST work

so when you select a team... you will need to update your 3rd table
Sorry, only registered users may post in this forum.

Click here to login