Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [HTML][MySQL][PHP]Inkrementacja wierszy w bazie
redtyper
post
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 22.12.2017

Ostrzeżenie: (0%)
-----


Witam,
Posiadam taki formularz dodający/edytujący zdarzenie.
Mianowicie, chciałym rozszerzyć go o funkcję automatycznego dodania wartości (tak jak działa inkrementacja i++).
Posiadam w bazie tabele statistic_tips zawierającą dwa wiersze stat_win oraz stat_false
Tylko podczas edycji (bo w gruncie reczy edycja będzie polegała przeważnie na zmianie jednego rekordu) po dokonaniu zmian, chciałbym aby w zależności od wybranej opcji (win, loss z results) automatycznie powiększało wiersz stat_win bądź stat_false.
Jak to osiągnąć moi drodzy ?
Podpowiecie? Ewentualnie z miłą chęcią usłyszę lepsze rozwiązania.
Przepraszam za pewnie błache pytanie, ale jestem początkujący (IMG:style_emoticons/default/smile.gif)
Na czerwono zaznaczyłem fragment, gdzie próbowałem jakoś to wykombinować, ale niestety nie udało się.
  1. <div class="panel-body">
  2. <div class="row">
  3. <div class="col-lg-3">
  4. <form role="form" method="post" action="" onreset="resetAction()">
  5. <div class="form-group">
  6. <label>Dane o meczu</label>
  7.  
  8. <input class="form-control" placeholder="Data meczu" type="datetime-local" name="datentime" required><br>
  9. <input class="form-control" placeholder="Liga" name="league" required>
  10. </div>
  11. <div class="form-group">
  12. <label>Gospodarze</label>
  13. <input class="form-control" placeholder="Enter team name" name="team1" required>
  14. </div>
  15. <div class="form-group">
  16. <label>Goście</label>
  17. <input class="form-control" placeholder="Enter team name" name="team2" required>
  18. </div>
  19. <div class="form-group">
  20. <label>Typ</label>
  21. <input class="form-control" placeholder="Enter prediction" name="draw" required>
  22. </div>
  23. <label>Status typu</label>
  24. <div class="radio">
  25. <label><input type="radio" name="results" value="actual">Kupon w trakcie</label>
  26. </div>
  27. <div class="radio">
  28. <label><input type="radio" name="results" value="win">Kupon wygrany</label>
  29. </div>
  30. <div class="radio">
  31. <label><input type="radio" name="results" value="loss">Kupon przegrany</label>
  32. </div>
  33. <div>
  34.  
  35. </div>
  36. <button type="submit" class="btn btn-default" name="add_tip">Dodaj typ</button>
  37. <button type="reset" class="btn btn-default">Reset</button>
  38.  
  39. </form>
  40. <?php
  41. function undefinedIndex(){
  42. }
  43. set_error_handler("undefinedIndex", E_NOTICE);
  44. if(isset($_POST['add_tip'])){
  45. $team1=$_POST['team1'];
  46. $team2=$_POST['team2'];
  47. $league=$_POST['league'];
  48. $datentime=$_POST['datentime'];
  49. $draw=$_POST['draw'];
  50. $results=$_POST['results'];
  51. $sql_insert="INSERT INTO premium_tips(datentime, league, team1, team2, draw, results) VALUES ('$datentime','$league','$team1','$team2','$draw','$results')";
  52. if ($conn->query($sql_insert) === TRUE) {
  53. } else {
  54. echo "Error: " . $sql . "<br>" . $conn->error;
  55. }
  56. }
  57. if(isset($_POST['update_tip'])){
  58. $team1=$_POST['team1u'];
  59. $team2=$_POST['team2u'];
  60. $league=$_POST['leagueu'];
  61. $datentime=$_POST['datentimeu'];
  62. $draw=$_POST['drawu'];
  63. $results=$_POST['resultsu'];
  64. $id=$_POST['id'];
  65. [color="#FF0000"] $win1=$mysqli->query('SELECT stat_win FROM statistic_tips');
  66. $loss1=$mysqli->query('SELECT stat_false FROM statistic_tips');
  67. if($results=="win"){
  68. $sql_insert="
  69. INSERT INTO statistic_tips (stat_win) VALUES '$win1+=1'";
  70. }
  71. if($results=="loss"){
  72. $sql_insert="
  73. INSERT INTO statistic_tips (stat_false) VALUES '$loss1+=1'";
  74. }[/color]
  75. $sql_insert="
  76. UPDATE premium_tips SET datentime='$datentime', league='$league',team1='$team1', team2='$team2',draw='$draw', results='$results' WHERE id='$id'";
  77. if ($conn->query($sql_insert) === TRUE) {
  78. } else {
  79. echo "Error: " . $sql . "<br>" . $conn->error;
  80. }
  81. }
  82. ?>
  83. </div>
  84. <div class="col-lg-9" id="del_status"></div>
  85. <div class="col-lg-9 tooltip-demo">
  86. <strong>Predictions:</strong><br>Hover on titles for more info
  87. <div id="gotten_info"></div>
  88. </div>


Ten post edytował redtyper 22.12.2017, 04:45:18
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 26.09.2025 - 13:27