CodeIgniter Forums
IF Query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: General (https://forum.codeigniter.com/forumdisplay.php?fid=1)
+--- Forum: Regional User Groups (https://forum.codeigniter.com/forumdisplay.php?fid=25)
+--- Thread: IF Query (/showthread.php?tid=70154)



IF Query - Germanikus - 03-01-2018

Hello everybody,
I have a problem with an IF.
For this query, the total amount of the article should be checked.
If it is exactly 0, an update will be executed.
But if it is above that, it should be ignored.

Example:
The database says I have 5 batteries.
I sell 5, so an update will be executed.

Here are the code:
Model

PHP Code:
    public function karte_gelagert_sum($slug false) {
        $this->db->select('SUM(tb_karte_anzahl) as count');
        $this->db->where('db_karte.tb_karte_karten_stats'$slug);
        $query $this->db->get('db_karte');
        return $query->row_array();
    }

 
   public function insert_artikel($slug) {
 
       if (isset($_POST['add_insert_artikel'])) {
            if(
$this->input->post('add_karte_anzahl') == 0) {
            
// if(0 == 0) {
                
$this->db->set('tb_ygo_karten_stats_aktiv'0);
                
// $this->db->set('tb_ygo_karten_stats_aktiv', 1);
                
$this->db->where('tb_ygo_karten_stats_id'$slug);
                
$this->db->update('db_ygo_karten_stats');
            }
        }
    } 


view:

Code:
<?php echo form_open('Karte/insert_artikel'); ?>
<input type="text" name="add_karte_anzahl" value="<?php echo $test['count']; ?>"><!-- total quantity -->
<input type="hidden" name="add_karte_menge[<?php echo $edition_views['tb_karte_id']; ?>]" value="5"><!-- sale volume -->
<button name="add_insert_artikel" type="submit" required class="btn btn-default btn-xs" data-toggle="tooltip" data-placement="top" title="<?php echo $this->lang->line('all_button_verkauf'); ?>"><span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span></button>
<?php echo form_close(); ?>

I do not understand why this does not update.


RE: IF Query - InsiteFX - 03-02-2018

Try this, first get it to work then tweak it out.

PHP Code:
public function insert_artikel($slug)
{
 
   if (isset($_POST['add_insert_artikel']))
 
   {
 
       if ($this->input->post('add_karte_anzahl') == 0)
 
       {
 
           $this->db->set('tb_ygo_karten_stats_aktiv'0);
 
       }
 
       else
        
{
 
           $this->db->set('tb_ygo_karten_stats_aktiv'1);
 
       }

 
           $this->db->where('tb_ygo_karten_stats_id'$slug);
 
           $this->db->update('db_ygo_karten_stats');
 
       }