Welcome! Log In Create A New Profile

Advanced

Team selection

Posted by Mac 
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
Mac
Team selection
July 25, 2013 05:39PM
Remember, in the portfolio a requirement is a team selection function. It is not described in the tut letter because you need to figure it out yourself (not all can be given!).

To help you. a page is presented that draws information from the fixtures table. It presents the positions as described in the database. You pull the players information from the players db, from where you make your selections.

Now figure that out, and give tips. I will monitor.
Re: Team selection
September 03, 2013 11:43PM
Hi Sir,

I have a question: My team selection page does not display different fields ie Wing and Fullback but rather a Position field that pulls position data from the player table.

Is this correct or have I misunderstood ?

Thanks very much.
avatar
Mac
Re: Team selection
September 04, 2013 08:06AM
Yes, that is ideal
Re: Team selection
September 12, 2013 05:01PM
hi
please help me, I created a table form local host as mentioned in TUT and I studied from home n learn page.
Now i am trying to read it using all functions on how to read from the local host. I'm using xampp

It display that Database not find on the page.

Am I missing something because i tested form server.
Please help if i did it wrong.
avatar
Mac
Re: Team selection
September 13, 2013 07:14AM
If the db is not found, then it is not found - i.e. the code does not point to it.. add a 'or die' like here under which should provide more information.

Language: PHP
$db_found = mysql_select_db($database) or die(mysql_error());
avatar Re: Team selection
September 18, 2013 01:14PM
i understand do we use drop down list
avatar
Mac
Re: Team selection
September 18, 2013 02:22PM
It is better to add a drop-down list to select a player for each position
Re: Team selection
September 19, 2013 10:27AM
My submit button is not functioning well in the edit.php page
and to my surprise no error message is displayed.
avatar
Mac
Re: Team selection
September 19, 2013 10:36AM
An error message needs to be added!
Re: Team selection
September 19, 2013 12:35PM
Is it compalsory to you a drop down list from team selection?
avatar
Mac
Re: Team selection
September 19, 2013 12:46PM
You decide.
Re: Team selection
September 23, 2013 12:19PM
Good morning!
I don't know if i'm wrong but i was thinking having a drop down list for the fixture id and one for each position with a submit button to send the selected data to the database.
That's what i did.The only problem i have is the submit button is sending only data from one position and the fixture_id is always 0,i don't know why but i'm working on it.Hope to find where i'm wrong soon
avatar
Mac
Re: Team selection
September 23, 2013 12:44PM
The fixture id is never selected by the user - it is simply sent (as a hidden field) together with the choice of selected players.
avatar Re: Team selection
September 23, 2013 08:46PM
sir i didn't use a drop down list i manually input the team positions in a text field; is this ohk
avatar
Mac
Re: Team selection
September 25, 2013 08:08AM
If people type the position in and they make a typing mistake, then it means there is a data integrity problem. So one should not type a position or a player's name
Re: Team selection
September 25, 2013 01:11PM
owk , so could this be the course of my team selection.php page not to link with the fixture.php for selected players that must appear in my public_fixtures.php page,
i`m asking coz i`ve inserted fixture_id in a textbox area instead of hiding it...and the two do not link
avatar
Mac
Re: Team selection
September 25, 2013 03:48PM
You have a fixture. You send the fixture id to the team selection page, because that will allow you to enter (and associate) players selected for that fixture. Thus, you need to link a fixture id to a player id.

On the public fixtures page, you simple echo the results - you have a player id and a fixture id, so you just need to draw the relevant information from the relevant tables. When the player needs to be edited, you still need to send the fixture id (and the player id) to ensure you edit the correct row of the player in the team selection table.
Re: Team selection
September 25, 2013 03:55PM
We have a field named position in the list of players. Do have to insert the fields for position created for selection into these field. Second question is if we want to read al three tables do we use join tables statements?
avatar
Mac
Re: Team selection
September 25, 2013 04:02PM
You SHOULD use JOINS... but I also accept it is a steep learning curve - thus I accept nested db statements. It is about developing logic.... This is how one get to understand functions - is there a shorter and better way to code this? Also, the best route is to have position as a row rather than a column.
Re: Team selection
September 25, 2013 07:34PM
guys i have a problem , my site works well when i test it on opera and chromi browser but i can't say the same thing for IE browser,what i would like to know is which browser do the mark use when they mark the portfolio ?
cos i cant re due my portfolio from start to support IE too
avatar
Mac
Re: Team selection
September 26, 2013 07:42AM
The browser should not make any difference because PHP is not interpreted by the browser - it just displays the result. If you used JS, which is less reliable across browsers, then that is your choice....
Re: Team selection
September 28, 2013 05:00PM
[The fixture id is never selected by the user - it is simply sent (as a hidden field) together with the choice of selected players]
I managed to use the fixture_id directly from the fixtures page to the selection page,now when i select players and submit to the database,only the latest selection is added,everytime i add a selection i have the same latest selection in the database.I don't know what i'm doing wrong he.Here is my insert query:
Language: PHP
<?php if (isset($_POST[';submit';])){ $id = $_GET[';fixture_id';]; $sql="INSERT INTO selection (fixture_id,point_guard,shooting_guard,small_forward,power_forward,center)VALUES(';$id';,';$pg';,';$sg';,';$sf';,';$pf';,';$center';)"; $qry = mysql_query($sql); if (!$qry) { die(';Error: '; . mysql_error($db_handle)); } } ?>
Any help will be much appreciated
avatar Re: Team selection
September 28, 2013 07:04PM
If your form method="POST", then all data, including hidden fields, will be in the $_POST array. -

Language: PHP
$id = $_POST[';fixture_id';]; // ???
Re: Team selection
September 30, 2013 10:17AM
Can i add "name" field in the selection table? because position i think is not enough for visitor to know which player was selected for the game!
avatar
Mac
Re: Team selection
September 30, 2013 01:32PM
You can add whatever you want in the table - it is for you to decide. It will all depend on how you see/code it.
Re: Team selection
October 01, 2013 07:35AM
Hello MAC
I have turned to numerous coding forums such as stackoverflow (click to see question) with my problem but I can not get a clear answer.
I want to know how would I go abouts getting values selected from MULTIPLE dropdown menus.

Ive been battling away with this:

Ive got a page where I pull names from players specific to their positions in a sport squad.
Example: I will display all the Wings in the squad using a dropdown where a coach can then pick his wing for the game.

There are dropdowns for each different position The aim of the page is to let the coach quickly select his team for a fixture.
Page displayed:


After the coach selected his team he will, select the opponents for which the selected team will play against.

When he clicks submit the selected oppents and players will get stored in two arrays which will get called to display the team selected and their opponents on a new page. (After which it will get uploaded to the DB.)
I am having trouble getting the values from the select list to display on the new page.
I guess I have to do something like this on the new page:

Language: PHP
foreach ($_REQUEST[';opponents';] as $opponents){ print $opponents; echo';<br>';; }

but it is not giving the desired results.

Strangely what gets printed is the variable name from the previous page select menu. Upon further inspection I did a vardump on the new page and it says that $opponenets gets passed a value of string which is the variable name and not the value thereof?

Some of my code looks like this any help would be greatly appreciated.
Language: PHP
if(isset($_POST["submit"])) { foreach ($_REQUEST[';opponents';] as $against){ var_dump($against); print $against; echo';<br>';; } } else { echo';<h1>Select your Team</h1>';; $x = array("THP", "HKR", "LHP", "LH", "FLH"); //players positions gets assigned to x which will be used to query the database echo ';<form name="playerselect" method="post" action="">';; //query database with different query after each loop for ($i = 0; sizeof($x) > $i; $i++) { //query where position field equeals variable x $result = mysql_query("SELECT `name`, `position` FROM `player_info` WHERE `position` = ';$x[$i]';") or die(mysql_error()) ; //Gets data from DB and assigns values to arrays below while($row = mysql_fetch_array($result)) { $playername[] = $row[';name';]; $position[] = $row[';position';]; } //print player position print $position[0]; echo';<br>';; //unset the array so that it is empty for the next query in the new loop unset($position); echo ';<select name="players[]" >'; ; foreach ($playername as $name ) { //Put playernames relevant to the position in the option element echo';<option value="$name" selected="selected">';.$name;';</option>';; echo';<br>';; } echo';</select>';; //unset array so that its contents is empty for the next query in the new loop unset($playername); echo';<br>';; }
avatar
Mac
Re: Team selection
October 01, 2013 08:33AM
Have a look/post the source code as printed by the browser here - it will help me understand something that you have not posted here.
What do you mean by "variable name from the .... select menu"?
avatar Re: Team selection
October 01, 2013 09:24AM
Not sure if I understand your problem correctly, but it seems very simple.
Each dropdown has a name - so you just recover each value from $_POST on the new page in the usual way.

$thp = $_POST['thp']; // where 'thp' is the name of the first dropdown etc.
$hkr = $_POST['hkr'];

etc., and then assign them to your array.
Re: Team selection
October 01, 2013 09:40AM
Thank you for the reply MAC
What I meant when I referred to the, "variable name in the...select menu" was that, the array $name is passed to the option elements to display the data which $name holds.

Language: PHP
echo ';<select name="players[]" >'; ; foreach ($playername as $name ) { //Put playernames relevant to the position in the option element echo';<option value="$name" selected="selected">';.$name;';</option>';; echo';<br>';; }

notice the variable $name between the option tags

Here is the output from browser


Now I need to find out which elements of the array $name was selected from the dropdown menu.



I try to do this on the next page using the $_REQUEST super global

Language: PHP
foreach ($_REQUEST[';players';] as $selected_player) { print $selected_player echo';<br>';; }
Now the code above should print all the selected players from the previous page but strangely it only prints the arrays actual name, which is $name...?

Ill try to give more info
My logic for the page is this

firstly I declare a variable $x and assign to it the values of the different positions in the team
Language: PHP
$x = array("THP", "HKR", "LHP", "LH", "FLH"); //players positions gets assigned to x which will be used to query the database

Now I use a For loop to loop over however many elements is in the $x array
Language: PHP
for ($i = 0; sizeof($x) > $i; $i++)

Inside the For loop I have a mysql_query which queries the database with the value of variable $x
Language: PHP
//query where position field equeals variable x $result = mysql_query("SELECT `name`, `position` FROM `player_info` WHERE `position` = ';$x[$i]';") or die(mysql_error()) ;

Next I use a whileloop to get Data from database and assign it to array
Language: PHP
while($row = mysql_fetch_array($result)) { $playername[] = $row[';name';]; $position[] = $row[';position';]; }

I then extract the values from the array $playername with a foreach loop as such
Language: PHP
echo ';<select name="players[]" >'; ; foreach ($playername as $name ) { //Put playernames relevant to the position in the option element echo';<option value="$name" selected="selected">';.$name;';</option>';; echo';<br>';; } echo';</select>';;


Now a dropdown menu was created for the 1st position in the team.

unset the arrays values so that it is empty for next loop as such
Language: PHP
unset($playername);

The forloop first iteration is completed
The forloop starts again querying the database for players who plays the 2nd position in the team
: and so on

Everything is working perfectly I just need a way to get the values which was selected.....
avatar
Mac
Re: Team selection
October 01, 2013 11:41AM
Yes I got the logic which is ok..

Have a look at your page source - $name IS the value that is passed instead of the person's name i.e. in the page source it should be Oliver, for example, and not $name

Each person has their own preference - I prefer to type it as follows:

Language: PHP
echo "<option value=\"$name\" selected=\"selected\">".$name;"</option>";   // in the page source then Oliver is the value   <select name="players[]" ><option value="Oliver" selected="selected">Oliver

Close correctly using an closing </option)! Why each option selected?
avatar Re: Team selection
October 01, 2013 11:53AM
<option value="$name" should contain the actual players name, otherwise the returned value will literally be $name.
Using a PHP variable in an HTML statement ?

You are preselecting all the options with selected="selected". Should only preselect one option per dropdown ?
(And have not enabled multiple selections).

<select name="players[]"> - Same for each dropdown ?
Should it not be "players[1]" "players[2]" etc.?


Edit: Sorry, Prof Mac reply had not been posted when I started.
Re: Team selection
October 03, 2013 07:39AM
I can fails if i did not comment my code? knowing that my application is working perfectly. and if i must comment my code how i must do it? line by line or page by page? the exams is just in the corner...
avatar
Mac
Re: Team selection
October 03, 2013 09:44AM
No, you cannot fail but we award marks for commenting. See the tut on how to comment.
Re: Team selection
October 11, 2013 12:54PM
sorry for late replys internet issues.but thanks alot for help my fixture.php is perfect now the fixture_id was the trick and I`m done with the portfolio now....
Re: Team selection
October 13, 2013 07:05PM
In my team_selection page, i have 4 arrays. I read the database,then check every row's position and assign it to the relevant array(goalkeepers,defenders,midfielders,strikers). From the arrays, i create checkboxes with the names from the arrays. There is too much coding,but i guess the logic count.
Re: Team selection
October 21, 2013 06:43AM
Hi there MAC
Just a quick one regarding my team selection page


My team is displayed in a dropdown menu. With a different dropdown menu for each different position.
Now the coach selects his team
He then selects the opponents against whom the selected team will play
He then clicks submit
When he clicks submit the isset() function is triggered which will upload the selected team to the selected_team table in my db

Ok that is easy enough and it is working. Here is my problem, lets say the coach wants to change his selection for a certain fixture. He then goes to the selection page again and redo the whole process described above. But what now happens is that the same fixture_id for opponents is uploaded to the database (only with different playernames where he changed his selection) thus creating duplicate entries.
Here is an example


Notice in above example that the 1st selection still remains. The second selection gets added below the first selection instead of replaicing the 1st selection. Thus creating duplicate entries
So my question is
How do I replace data in my table if duplicate entries are found?

Then one more question

What is the assestment criteria for the portfolio
Will points be awarded for the look and feel of your site?
Or is it purely based on the PHP code?
Thank you
avatar
Mac
Re: Team selection
October 21, 2013 09:56AM
An update should draw the current data from the table, which is then updated using the selection_id - not re-inserted. We mark the PHP code - not the look.
avatar Re: Team selection
October 21, 2013 10:02AM
You need to use UPDATE and not INSERT.

If your entries have different Primary Keys (Auto increment ?), then mySQL will not consider them to be duplicates.
You will need to DELETE them manually.
Re: Team selection
October 21, 2013 11:55AM
Selection_id with an attribute of auto increment is the PK because that is what it said we must do in the tut. Can I change my PK in the above table to fixture_id which will make much more sense. Unless im completely missing something
Thank you bigron & mac for the replies
avatar Re: Team selection
October 21, 2013 12:10PM
The Primary Key must be unique for each row.
Using fixture_id will not give you a unique PK for each row,
avatar
Mac
Re: Team selection
October 21, 2013 12:16PM
Using the selection_id you are ensured that you are updating the correct row. There should just be one row of information for Jannie Duplessus with the fixture id 6 - not two. He can only be selected in one position for this fixture. It is possible that you can have two players with the same name and surname - so you need something "else" to ensure you are drawing and updating the correct person, and that is what the selection_id provides you with.
Re: Team selection
October 22, 2013 05:00AM
DOH! That makes sense.

Thank you MAC.
Sorry, only registered users may post in this forum.

Click here to login