title: How to increment field value count using MySQL
body: <p>I have a student attendance table.</p>
  
  <p><strong>Fields/data sample</strong></p>
  
  <pre><code>id | studid | smonth | syear | total_p | total_a
  1  |   20   |   08   | 2015  |   1     |   0
  2  |   21   |   08   | 2015  |   0     |   1
  3  |   22   |   08   | 2015  |   1     |   0
  </code></pre>
  
  <p>Those are the first entered values. Then I again enter values for the same students (20,21,22) for the same month and year. All are present=1</p>
  
  <p><strong>Fields/data sample</strong></p>
  
  <pre><code>id | studid | smonth | syear | total_p | total_a
  1  |   20   |   08   | 2015  |   2     |   0
  2  |   21   |   08   | 2015  |   1     |   1
  3  |   22   |   08   | 2015  |   2     |   0
  </code></pre>
  
  <p>And I again enter values for the same students for the same month and year. All are present=1 so I want </p>
  
  <p><strong>Fields/data sample</strong></p>
  
  <pre><code>id | studid | smonth | syear | total_p | total_a
  1  |   20   |   08   | 2015  |   3     |   0
  2  |   21   |   08   | 2015  |   2     |   1
  3  |   22   |   08   | 2015  |   3     |   0 
  </code></pre>
  
  <p>What is the code for incrementing the <code>total_p</code> value by 1? It should first check the previous value then increment by 1.</p>
  
  <p>My controller code</p>
  
  <pre><code>$present = Input::get($student-&gt;id);
  if ($present == 1)
      {
          DB::table($wys_total_attend_table)-&gt;where('studid', $student-&gt;id)
              -&gt;where('smonth', $date_exploded[1])
              -&gt;where('syear', $date_exploded[2])
              -&gt;where('stotal_p', 1)
              -&gt;update(array(
                  'stotal_p' =&gt; 1 + 1,
              ));
          DB::table($wys_total_attend_table)-&gt;where('studid', $student-&gt;id)
              -&gt;where('smonth', $date_exploded[1])
              -&gt;where('syear', $date_exploded[2])
              -&gt;where('stotal_p', 0)
              -&gt;update(array(
                  'stotal_p' =&gt; 1,
                  'stotal_a' =&gt; 0,
              ));
      } elseif ($present == 0)
      {
          DB::table($wys_total_attend_table)-&gt;where('studid', $student-&gt;id)
              -&gt;where('smonth', $date_exploded[1])
              -&gt;where('syear', $date_exploded[2])
              -&gt;where('stotal_a', 1)
              -&gt;update(array(
                  'stotal_a' =&gt; 1 + 1,
              ));
          DB::table($wys_total_attend_table)-&gt;where('studid', $student-&gt;id)
              -&gt;where('smonth', $date_exploded[1])
              -&gt;where('syear', $date_exploded[2])
              -&gt;where('stotal_a', 0)
              -&gt;update(array(
                  'stotal_a' =&gt; 1,
              ));
          DB::table($wys_total_attend_table)-&gt;where('studid', $student-&gt;id)
              -&gt;where('smonth', $date_exploded[1])
              -&gt;where('syear', $date_exploded[2])
              -&gt;where('stotal_p', 1)
              -&gt;where('stotal_a', 0)
              -&gt;update(array(
                  'stotal_a' =&gt; 0 + 1,
              ));
      }
  </code></pre>