Jump to content


  • Posts

  • Joined

  • Last visited

NiallAA's Achievements


Newbie (1/5)




Community Answers

  1. Versions: Mysql 5.5, PHP 5.4 Evening folks, To simplify this request, I have a database of competition results. The table structure is as follows id (INT), date (DATE), pointsfor (TINYINT), pointsagainst (TINYINT) To summarise, if pointsfor > pointsagainst, the outcome on that date is considered a win. The result I'm looking to display is the 'winningest' run, i.e the start and end date of the most victories recorded in consecutive date order. I have no idea where to start with this, as I have yet to deal much with dates. Any help would be greatly appreciated. Thank you.
  2. Hi folks, Trying to run a MySQL UPDATE statement on a small table which basically has three fields. AppID, AppMatchID and AppPlayed. I have a form which sends two values via POST, which are app_played and matchid. app_played is a checkbox value. I am trying to update multiple rows at once using a submit button in the form, but coming into problems where it concerns where to check isset in the foreach loop. Here is my form: <form method="post" action="matchdata.php"> <input type="hidden" name="matchid" value="<?php echo $matchid ?>"> <?php // Get former players involved in opposition team $get_former_players = mysql_query(" SELECT L.OppID AS id, CONCAT(P.PlayerFirstName, ' ', P.PlayerLastName) AS name, L.OppPlayed AS played FROM db_opp_players L, tplss_players P WHERE L.OppMatchID = $matchid AND L.OppPlayerID = P.PlayerID ORDER BY P.PlayerLastName ASC, P.PlayerFirstName ASC",$connection) or die(mysql_error); while($opp_player_data = mysql_fetch_array($get_former_players)) { echo" <input type=\"hidden\" name=\"opp_id[]\" value=\"$opp_player_data[id]\"> $opp_player_data[name] "; if($opp_player_data['played'] == 1) echo"<input type=\"checkbox\" name=\"opp_played[]\" value=\"1\" CHECKED>"; else echo"<input type=\"checkbox\" name=\"opp_played[]\" value=\"1\">"; echo"Played?"; echo" <a href=\"matchdata.php?action=remove_from_opp_players&id=$opp_player_data[id]&matchid=$matchid\"> <img src=\"images/remove.gif\" border=\"0\" ALT=\"Remove\"></a> <br> "; } ?> <input type="submit" name="modify_opp_players" value="Update"> <? mysql_free_result($get_former_players); ?> </form> And here is my update command, after receiving POST information from the submit button. $opp_id = $_POST['opp_id']; $matchid = $_POST['matchid']; $opp_played = $_POST['opp_played']; foreach($opp_id as $key=>$played) { if(isset($opp_played['$key'])) { mysql_query(" UPDATE db_opp_players SET OppPlayed = '1' WHERE OppID = '$opp_id[$key]' ",$connection) or die(mysql_error()); } else { mysql_query(" UPDATE db_opp_players SET OppPlayed = '0' WHERE OppID = '$opp_id[$key]' ",$connection) or die(mysql_error()); } } Can anyone offer me a simpler solution, or better still something that works? At the moment the checkboxes either don't update, or only update the first entry.
  • 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.