Jump to content

NiallAA

Members
  • Posts

    13
  • Joined

  • Last visited

Everything posted by NiallAA

  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.
  3. As quick as I posted this I sussed it out. $j = 7;
  4. Hi all, I am trying to display a set of results in a table, and use the MySQL row index as a numbered bullet as the first column in each row. However, I intend to use two sets of six results. The first set of results should be numbered 1 to 6, the second set 7 to 12. At the moment, it returns 1 to 6, followed by another 1 to 6, understandably. Is there something simple I could be doing to the second query to change the index so that it starts at 7? Here is the code I am using to display the result of the second query: $j=1; $i=0; while($i< $qty) { if(isset($draw_line)) { for($k = 0 ; $k < sizeof($draw_line) ; $k++) { if($draw_line[$k] == $i) { $templine_width = $tb_width-20; echo" <tr> <td height=\"5\" colspan=\"20\" align=\"center\" valign=\"middle\"> <img src=\"images/line.gif\" width=\"$templine_width\" height=\"5\" ALT=\"\"><br> </td> </tr> "; } } } echo" <tr style=\"border-top: 0.5px;\"> <td align=\"left\" valign=\"middle\" bgcolor=\"$bg1\"><b>$j.</b></td> <td align=\"left\" valign=\"middle\" bgcolor=\"$bg1\"> "; if($team[$i] == "Dundee United") echo"<b>UNITED</b>"; else echo"<a href=\"opponent.php?opp=$teamid[$i]\">$team[$i]</a>"; echo" </td> <td align=\"center\" valign=\"middle\" bgcolor=\"$bg2\">$pld[$i]</td> <td align=\"center\" valign=\"middle\" bgcolor=\"$bg1\">$wins[$i]</td> <td align=\"center\" valign=\"middle\" bgcolor=\"$bg1\">$draws[$i]</td> <td align=\"center\" valign=\"middle\" bgcolor=\"$bg1\">$loses[$i]</td> <td align=\"center\" valign=\"middle\" bgcolor=\"$bg1\">$goals_for[$i]</td> <td align=\"center\" valign=\"middle\" bgcolor=\"$bg1\">$goals_against[$i]</td> <td align=\"center\" valign=\"middle\" bgcolor=\"$bg1\">$diff[$i]</td> <td align=\"center\" valign=\"middle\" bgcolor=\"$bg2\">$points[$i]</td> </tr> "; $i++; $j++; } Niall
  5. Thank you very much, that's a great help. I shall look into the use of mysql_real_escape_string once again. Whatever I did was not successful the first time. These textareas are to contain basic html, in particular <a href=""> tags in the middle of several paragraphs. The inverted commas seem to almost always inherit a \ when using mysql_real_escape_string, and add a further \ each time the box is saved. It'll take a bit of trial and error I suppose, but needs must, as I won't be on PHP 5.3 forever and I shall need to look into moving with the times. Thank you very much for your assistance.
  6. Thanks. I have done so Sanitising (I guess this should also be done using nl2br? ): $matchdata['report'] = str_replace('<br>',"\r\n", $matchdata['report']); User input field: <textarea name="report" cols="45" rows="15"><?php echo $matchdata['report'] ?></textarea>
  7. Hi all, This is a bit of a confusing one. I have been using a script for a while now, very basic, which submits a textarea via a form to a MySQL database using UPDATE. It's never been a problem on the GoDaddy servers I'm using which run on PHP 5.3 and MySQL 5.5. I am trying to use the same script on a 1&1 internet hosted package, which uses PHP 5.4 and MySQL 5.1. It throws up MySQL syntax errors when I submit the exact same form. Before the UPDATE statement, I define a variable using $_POST info and strip the white space and replace the line breaks. $report = str_replace("\r\n",'<br>', trim($_POST['report'])); Is this just a case of differing MySQL versions? Niall
×
×
  • 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.