Jump to content

stb74

Members
  • Posts

    71
  • Joined

  • Last visited

Everything posted by stb74

  1. Doh My server copy is running 5 but for some stupid reason my xammp was running 4.
  2. I as able to get it working by this. function sortTable($array) { foreach ($array as $key => $row) { $Points[$key] = $row['Points']; $GoalDiff[$key] = $row['GoalDiff']; $GoalsFor[$key] = $row['GoalsFor']; $teamName[$key] = $row['teamName']; } array_multisort($Points, SORT_DESC, $GoalDiff, SORT_DESC, $GoalsFor, SORT_DESC, $teamName, SORT_STRING, $array); return $array; } Is this way ok.
  3. Hi I am trying to create a function that will enable me to sort a soccer league table. Sort will be on several fields Points GoalDiff GoalsFor I found this example that I though might help me find a solution but it gives an error Parse error: parse error, unexpected T_NEW in D:\XAMPP Web\xampp\htdocs\nifootball\sort.php on line 29 function sortDataSet(&$dataSet) { $args = func_get_args(); $callString = 'array_multisort('; $usedColumns = array(); for($i = 1, $count = count($args); $i < $count; ++$i) { switch(gettype($args[$i])) { case 'string': $callString .= '$dataSet[\''.$args[$i].'\'], '; array_push($usedColumns, $args[$i]); break; case 'integer': $callString .= $args[$i].', '; break; default: throw new Exception('expected string or integer, given '.gettype($args[$i])); } } foreach($dataSet as $column => $array) { if(in_array($column, $usedColumns)) continue; $callString .= '$dataSet[\''.$column.'\'], '; } eval(substr($callString, 0, -2).');'); } /* example usage */ /* example usage */ $latestPost = array( 'team' => array( '0', '1', '2', '4', '5' ), 'name' => array( 'team1', 'team2', 'team3', 'team4', 'team5' ), 'date' => array( '10', '8', '12', '20', '4' ) ); sortDataSet($latestPost, 'name', SORT_DESC, SORT_STRING, 'team', SORT_DESC, SORT_STRING); echo '<pre>'; print_r($latestPost); echo '</pre>'; ?>
  4. I have a page that I export divisions from a league one after each other to a text file. I can get it to export the data but once I add the array_multisort some teams are placed in the wrong division.  It works fine for one division then I added the code following code so I can export each division in the league.  Can anyone see whats wrong with the array_mulitsort. [code] do { } $defaultdivisionid++; } while ($row_divisions = mysql_fetch_assoc($divisions)); [/code] Complete Code [code] <?php session_start(); //Connect to the database and select used database require('../dbconnect/config.php'); require('../dbconnect/dbconnect.php'); header ("Content-type: application/csv"); header ("Content-Disposition: inline; filename=$row_filename[name]_tables.txt"); do { // Column Headers echo("Team\t"); echo("P\t"); echo("W\t"); echo("D\t"); echo("L\t"); echo("F\t"); echo("A\t"); echo("Pts\t\n"); // Get Match Teams for selected Division & Season. mysql_select_db("$dbname", $dbconnect); $query_get_teams = " SELECT DISTINCT O.teamName AS name, O.teamID AS id FROM leaguestats_teams O, leaguestats_matches LM WHERE LM.matchSeasonID LIKE '$defaultseasonid' AND LM.matchdivisionID = '$defaultdivisionid' AND (O.teamID = LM.matchHomeID OR O.teamID = LM.matchAwayID)"; $get_teams = mysql_query($query_get_teams, $dbconnect) or die(mysql_error()); $row_get_teams = mysql_fetch_assoc($get_teams); $totalRows_get_teams = mysql_num_rows($get_teams); // End Get Match Teams for selected Division & Season. // Start Loop and read teams in to Table. $i = 0; do { $team[$i] = $row_get_teams['name']; $teamid[$i] = $row_get_teams['id']; //$teamstatus[$i] = $row_get_teams['status']; Get data to calculate points etc....                       $points[$i] = $temp_points + ($wins[$i]*$for_win) + ($draws[$i]*$for_draw); $pld[$i] = $homewins[$i]+$homedraws[$i]+$homeloses[$i]+$awaywins[$i]+$awaydraws[$i]+$awayloses[$i]; $diff[$i] = ($homegoals[$i] + $awaygoals[$i]) - ($homegoalsagainst[$i] + $awaygoalsagainst[$i]); $i++; } while($row_get_teams = mysql_fetch_assoc($get_teams)); // End Loop and read teams in to Table. $qty = $totalRows_get_teams; // Sort By Points array_multisort($points, SORT_DESC, SORT_NUMERIC, $diff, SORT_DESC, SORT_NUMERIC, $goals_for, SORT_DESC, SORT_NUMERIC, $wins, SORT_DESC, SORT_NUMERIC, $goals_against, SORT_ASC, SORT_NUMERIC, $draws, $loses, $pld, SORT_DESC, SORT_NUMERIC, $team, $homewins, $homedraws, $homeloses, $awaywins, $awaydraws, $awayloses, $homegoals, $homegoalsagainst, $awaygoals, $awaygoalsagainst); $i=0; while($i < $qty) { echo "$team[$i]\t"; echo "$pld[$i]\t"; echo"$wins[$i]\t"; echo"$draws[$i]\t"; echo"$loses[$i]\t"; echo"$goals_for[$i]\t"; echo"$goals_against[$i]\t"; echo"$points[$i]\t"; $i++; echo "\n"; } echo "\n"; $defaultdivisionid++; } while ($row_divisions = mysql_fetch_assoc($divisions)); ?> [/code]
  5. I have a page that I export divisions from a league one after each other to a text file. I can get it to export the data but once I add the array_multisort some teams are placed in the wrong division.  It works fine for one division then I added the code following code so I can export each division in the league.  Can anyone see whats wrong with the array_mulitsort. [code] do { } $defaultdivisionid++; } while ($row_divisions = mysql_fetch_assoc($divisions)); [/code] Complete Code [code] <?php session_start(); //Connect to the database and select used database require('../dbconnect/config.php'); require('../dbconnect/dbconnect.php'); header ("Content-type: application/csv"); header ("Content-Disposition: inline; filename=$row_filename[name]_tables.txt"); do { // Column Headers echo("Team\t"); echo("P\t"); echo("W\t"); echo("D\t"); echo("L\t"); echo("F\t"); echo("A\t"); echo("Pts\t\n"); // Get Match Teams for selected Division & Season. mysql_select_db("$dbname", $dbconnect); $query_get_teams = " SELECT DISTINCT O.teamName AS name, O.teamID AS id FROM leaguestats_teams O, leaguestats_matches LM WHERE LM.matchSeasonID LIKE '$defaultseasonid' AND LM.matchdivisionID = '$defaultdivisionid' AND (O.teamID = LM.matchHomeID OR O.teamID = LM.matchAwayID)"; $get_teams = mysql_query($query_get_teams, $dbconnect) or die(mysql_error()); $row_get_teams = mysql_fetch_assoc($get_teams); $totalRows_get_teams = mysql_num_rows($get_teams); // End Get Match Teams for selected Division & Season. // Start Loop and read teams in to Table. $i = 0; do { $team[$i] = $row_get_teams['name']; $teamid[$i] = $row_get_teams['id']; //$teamstatus[$i] = $row_get_teams['status']; Get data to calculate points etc....                       $points[$i] = $temp_points + ($wins[$i]*$for_win) + ($draws[$i]*$for_draw); $pld[$i] = $homewins[$i]+$homedraws[$i]+$homeloses[$i]+$awaywins[$i]+$awaydraws[$i]+$awayloses[$i]; $diff[$i] = ($homegoals[$i] + $awaygoals[$i]) - ($homegoalsagainst[$i] + $awaygoalsagainst[$i]); $i++; } while($row_get_teams = mysql_fetch_assoc($get_teams)); // End Loop and read teams in to Table. $qty = $totalRows_get_teams; // Sort By Points array_multisort($points, SORT_DESC, SORT_NUMERIC, $diff, SORT_DESC, SORT_NUMERIC, $goals_for, SORT_DESC, SORT_NUMERIC, $wins, SORT_DESC, SORT_NUMERIC, $goals_against, SORT_ASC, SORT_NUMERIC, $draws, $loses, $pld, SORT_DESC, SORT_NUMERIC, $team, $homewins, $homedraws, $homeloses, $awaywins, $awaydraws, $awayloses, $homegoals, $homegoalsagainst, $awaygoals, $awaygoalsagainst); $i=0; while($i < $qty) { echo "$team[$i]\t"; echo "$pld[$i]\t"; echo"$wins[$i]\t"; echo"$draws[$i]\t"; echo"$loses[$i]\t"; echo"$goals_for[$i]\t"; echo"$goals_against[$i]\t"; echo"$points[$i]\t"; $i++; echo "\n"; } echo "\n"; $defaultdivisionid++; } while ($row_divisions = mysql_fetch_assoc($divisions)); ?> [/code]
  6. I have a javascript menu that generates the menus from mysql tables. Menu displays league tables. Premier League       Division 1       Division 2 I want to be able to use the same file for each link so If I click on Division 1 it opens tables.php as well as Division 2 it will open tables.php. What I need is that when I click on Division 1, I set a variable and pass it into the tables.php file.
  7. Two teams can only play each other twice. A v B B v A I wanted to add a check that stopped me adding any of the matchs a second time. I believe I have sorted it out now anyway.
  8. you will have say your index file. index.php <html> <head> <title>Form</title> </head> <body> <form action="insert.php" method="post">Make: <input type="text" value="" name="[color=red]make[/color]"> Model: <input type="text" value="" name="[color=red]model[/color]"> <input type="[color=red]submit[/color]" value="Submit Query"> </form> </body> </html> then the insert.php  will have the details that your are using from the form (red).  insert.php (database connection details) $submit = $_POST['submit']; if($submit) {  $make= trim($_POST['make']);     $model= trim($_POST['model']);       mysql_query(" INSERT INTO database SET model = '$model',         make = '$make' ",$dbconnect) or die(mysql_error()); {
  9. Tracey I maybe wrong but in the insert.php you should just have the code that is going to insert the data into the database. $submit = $_POST['submit']; if($submit) { $make= trim($_POST['make']); $model= trim($_POST['model']);         //code to insert data to database. {
  10. try puting this on the end while ($row = mysql_fetch_array($seller))         {         echo "$row[username]";       } See if you get any output
  11. As you can tell I don't know what I am doing but I am making more of an effort in trying to explain than you are trying to help.
  12. I thought the code works but not the way I want it. [code] $query = " SELECT COUNT(*) AS found FROM downarea_matches AS LM WHERE (LM.matchHomeID = '" . $home[$i] . "' AND LM.matchAwayID = '" . $away[$i] . "' OR LM.matchHomeID = '" . $away[$i] . "' AND LM.matchAwayID = '" . $home[$i] . "') AND matchDivisionID = '$divisionid' AND matchSeasonID = '$seasonid'"; $result = mysql_query ( $query ); $total  = mysql_fetch_assoc ( $result ); if ( $total['found'] > 0 ) { echo 'sorry match already exists'; } else { // //Writes the data [/code] This code will match if hometeam AND awayteam OR awayteam and hometeam is present in the database. Its a bit hard to explain, but I will try. In a season two teams will play each other twice 1. Man U v Arsenal 2. Arsenal v Man U If I want to add match 1. but it already exists then flag error and if I want to add match 2 but exists then flag error.
  13. Cheers I had tried that earlier but gave up when it didn't work.  Must have had bad code somewhere.  Pasted in yours and works grand. Now that I have that sorted, would it be possible to add another query to it. I have another field called matchInfo, that if the match has been postponed or abondoned I would put a P or A in this field.  So that when I display the match for the users they see it as Man Utd P - P Arsenal. With the above code it stops me adding matches that I have already entered, but can I allow for the postponed games. Thanks
  14. No When I enter a match for a date. 2005-11-12 Man Utd - Arsenal If I go back later and add another match to that date, the following code checks that the teams are not already added to a match. [code] // //Query to check if home or away team already exists in the current day // $query = mysql_query(" SELECT LM.matchID FROM nafl_matches LM WHERE (LM.matchHomeID = '$home[$i]' OR LM.matchAwayID = '$home[$i]' OR LM.matchHomeID = '$away[$i]' OR LM.matchAwayID = '$away[$i]') AND LM.matchDate = '$dateandtime' ", $dbconnect) or die(mysql_error()); if(mysql_num_rows($query) == 0) { // //Writes the data // } else { echo "Match Exists"; } [/code] With the previous code I cannot add the same match on the same date, but I can add it multiple times on different dates. I think the code should be something like [code] // //Query to check for home game // $homematch = mysql_query(" SELECT LM.matchID FROM nafl_matches LM WHERE (LM.matchHomeID = '$home[$i]' AND LM.matchAwayID = '$away[$i]') ", $dbconnect) or die(mysql_error()); // //Query to check for away game // $awaymatch = mysql_query(" SELECT LM.matchID FROM nafl_matches LM WHERE (LM.matchHomeID = '$away[$i]' AND LM.matchAwayID = '$home[$i]') ", $dbconnect) or die(mysql_error()); I would need to combine the queries that if any are true that it displays an error. [/code]
  15. When entering a socccer match I would like to check to see if the match exists already in the database. I have the following to check for the current date. [code] SELECT LM.matchID FROM bbob_matches LM WHERE (LM.matchHomeID = '$home[$i]' OR LM.matchAwayID = '$home[$i]' OR LM.matchHomeID = '$away[$i]' OR LM.matchAwayID = '$away[$i]') AND LM.matchDate = '$dateandtime' [/code] Can anyone help with the code that I need to check all other dates.
  16. I enter matches into a form by date.  If I then click on the date I dislay that matches that are scheduled on that date. I have the option of changing the date or scores in the matches. The only part that is not working at the moment is the date field.  When I click to update the records the date field is being blanked out. Here is the form for displaying the selected matches. [code] <?php $date = $_REQUEST['date']; $get_matches = mysql_query(" SELECT LM.matchDate AS matchdate, DAYOFMONTH(LM.matchDate) AS dayofmonth, MONTH(LM.matchDate) AS month, YEAR(LM.matchDate) AS year, LM.matchID AS mid, LM.matchHomeID AS homeid, LM.matchAwayID AS awayid, LM.matchHomeGoals AS homegoals, LM.matchAwayGoals AS awaygoals, LM.matchInfo AS info FROM leaguestats_matches LM WHERE LM.matchDivisionID = '$divisionid' AND LM.matchDate = '$date' ", $dbconnect) or die(mysql_error()); // //Query to get date // $get_match = mysql_query(" SELECT DAYOFMONTH(LM.matchDate) AS dayofmonth, MONTH(LM.matchDate) AS month, YEAR(LM.matchDate) AS year FROM leaguestats_matches LM WHERE LM.matchDivisionID = '$divisionid' AND LM.matchDate = '$date' LIMIT 1 ", $dbconnect) or die(mysql_error()); $datedata = mysql_fetch_array($get_match); mysql_free_result($get_match); $get_teams = mysql_query(" SELECT teamID AS id, teamName AS name FROM leaguestats_teams WHERE teamdivisionID = '$divisionid' ORDER BY teamName ", $dbconnect) or die(mysql_error()); ?> <form method="post" action="<?php echo "$PHP_SELF?sessioid=$sessio" ?>"> <h1>Modify matches</h1> <?php echo "$date"; ?> <table cellspacing="1" cellpadding="1" border="0">   <tr valign="top"> <td align="left" valign="top">Date and time: </td> <td align="left" valign="top"><select name="day"> <?php //Print the days for($i = 1 ; $i < 32 ; $i++) { if($i<10) { $i = "0".$i; } if($datedata['dayofmonth'] == $i) echo "<option value=\"$i\" SELECTED>$i</option>\n"; else echo "<option value=\"$i\">$i</option>\n"; } ?>   </select>   &nbsp;/&nbsp;   <select name="month"> <?php //Print the months for($i = 1 ; $i < 13 ; $i++) { if($i<10) { $i = "0".$i; } if($datedata['month'] == $i) echo "<option value=\"$i\" SELECTED>$i</option>\n"; else echo "<option value=\"$i\">$i</option>\n"; } ?>   </select>   &nbsp;/&nbsp;   <select name="year"> <?php //Print the years for($i = 2006 ; $i < 2020 ; $i++) { if($i<10) { $i = "0".$i; } if($datedata['year'] == $i) echo "<option value=\"$i\" SELECTED>$i</option>\n"; else echo "<option value=\"$i\">$i</option>\n"; } ?>   </select>            </td>   </tr> </table> <table cellspacing="1" cellpadding="1" border="0"> <tr> <td align="left" valign="middle"><b>Hometeam</b></td> <td align="left" valign="middle"><b>Awayteam</b></td> <td align="center" valign="middle"><b>GH</b></td> <td align="center" valign="middle"><b>GA</b></td> <td align="center" valign="middle"><b>Info</b></td> </tr> <?php // //Lets get all the matches from selected date to the form // $i = 0; while($matchdata = mysql_fetch_array($get_matches)) { // //Back to line 0 in the query if not the first loop // if($i>0) mysql_data_seek($get_teams, 0); echo' <tr> <td align="left" valign="middle"> '; echo"<select name=\"home[$i]\">"; while($data = mysql_fetch_array($get_teams)) { if($matchdata['homeid'] == $data['id']) echo"<option value=\"$data[id]\" SELECTED>$data[name]</option>\n"; } echo' </select> </td> <td align="left" valign="middle"> '; // //Back to line 0 in the query // mysql_data_seek($get_teams, 0); echo"<select name=\"away[$i]\">"; while($data = mysql_fetch_array($get_teams)) { if($matchdata['awayid'] == $data['id']) echo"<option value=\"$data[id]\" SELECTED>$data[name]</option>\n"; } echo" </select> </td> <td align=\"center\" valign=\"middle\"> <input type=\"text\" name=\"home_goals[$i]\" size=\"2\" value=\"$matchdata[homegoals]\"></td> <td align=\"center\" valign=\"middle\"> <input type=\"text\" name=\"away_goals[$i]\" size=\"2\" value=\"$matchdata[awaygoals]\"></td> <td align=\"center\" valign=\"middle\"> <input type=\"text\" name=\"info[$i]\" size=\"2\" value=\"$matchdata[info]\"></td> </tr> <input type=\"hidden\" name=\"mid[$i]\" size=\"2\" value=\"$matchdata[mid]\"> "; $i++; } mysql_free_result($get_matches); mysql_free_result($get_teams); ?> </table> You can't change home or away team in this mode. <br> Click the match to modify home/away team.<br> <br> <input type="hidden" name="qty" value="<?= $i ?>"> <br> <input type="submit" name="modifyall_submit" value="Click here to modify the matches"> </form> [/code] Here is the code for updating the database. [code] <?php // //Updates the last_updated column in preferences // mysql_query(" UPDATE `leaguestats_divisions` SET `last_updated` = CURRENT_TIMESTAMP WHERE `divisionID` = '$divisionid'" , $dbconnect) or die(mysql_error()); $year = $_POST['year']; $month = $_POST['month']; $day = $_POST['day']; $qty = $_POST['qty']; // //Check the submitted form // $i = 0; while($i < $qty) { $mid = $_POST['mid']; $dateandtime = $year."-".$month."-".$day; $home = $_POST['home']; $away = $_POST['away']; $home_goals = $_POST['home_goals']; $away_goals = $_POST['away_goals']; $info = $_POST['info']; // //Set default // $home_winner = -1; $home_loser = -1; $home_tie = -1; $away_winner = -1; $away_loser = -1; $away_tie = -1; // //Home wins // if($home_goals[$i] > $away_goals[$i]) { $home_winner = $home[$i]; $away_loser = $away[$i]; } // //Away wins // elseif($home_goals[$i] < $away_goals[$i]) { $away_winner = $away[$i]; $home_loser = $home[$i]; } // //Draw // elseif($home_goals[$i] == $away_goals[$i]) { $home_tie = $home[$i]; $away_tie = $away[$i]; } if($home_goals[$i] == '' || $away_goals[$i] == '' || !is_numeric($home_goals[$i]) || !is_numeric($away_goals[$i])) { mysql_query(" UPDATE leaguestats_matches SET matchDivisionID = '$divisionid', matchSeasonID = '$seasonid', matchDate = '$dateandtime', matchHomeID = '$home[$i]', matchAwayID = '$away[$i]', matchHomeWin = '-1', matchHomeLose = '-1', matchAwayWin = '-1', matchAwayLose = '-1', matchHomeDraw = '-1', matchAwayDraw = '-1', matchHomeGoals = NULL, matchAwayGoals = NULL, matchInfo = '$info[$i]' WHERE matchID = '$mid[$i]' ", $dbconnect) or die(mysql_error()); } else { mysql_query(" UPDATE leaguestats_matches SET matchDivisionID = '$divisionid', matchSeasonID = '$seasonid', matchDate = '$dateandtime', matchHomeID = '$home[$i]', matchAwayID = '$away[$i]', matchHomeWin = '$home_winner', matchHomeLose = '$home_loser', matchAwayWin = '$away_winner', matchAwayLose = '$away_loser', matchHomeDraw = '$home_tie', matchAwayDraw = '$away_tie', matchHomeGoals = '$home_goals[$i]', matchAwayGoals = '$away_goals[$i]', matchInfo = '$info[$i]' WHERE matchID = '$mid[$i]' ", $dbconnect) or die(mysql_error()); } $i++; } header("Location: $PHP_SELF?sessioid=$sessio"); ?> [/code]
  17. I know,  I was quite chuffed that I got he export working.  And it looks grand to me.  Unfortunately the quark is really old and it would be too much to upgrade. I will just have to go with what I have and hope something will come up in the future. Thanks for the input.
  18. Thats what I will be doing, I only have to do this once a week but have to do 60. When I open the scores sheet in excel it formats some of the damn scores as dates.
  19. I believe it is an issue with quark as it works fine  in version 7 of quark. But the version i need it to export to is old.  If it can't be done then its fine.  But if i resave it from excel it will read it ok. Thanks
  20. When I export the league data into the tab delimited text file, it works great. This then has to be imported into quark express. If i try to import the tab delimited text file, the tabs are gone and the text flows entry after entry. To get it to work I have to open in excel and then save as tab delimited text, then import into quark. It just seems that there is something missing from the export from php.
  21. After thinking I have sorted out the export issue, it works to a certain extent. I am able to export the league tables and fixtures into a tab delimited txt file.  But when I import it into Quark Express the formatting is being lost. I have to them open in excel and save as tab delimited txt file and this works. Can anyone help with what I need to add to keep the formatting intact. Cheers
  22. Don't matter anymore, after much trial an error I have worked it out.
  23. After a lot of trial and error I have gotten it working :P Its is working fine for the default division, but I would like to get it working for all divisions in the database. I have added the following aroung the main code. do { } while($row_divisions = mysql_fetch_assoc($divisions)); How do I increment the division.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.