Welcome Guest, Not a member yet? Register   Sign In
IF Query
#1

(This post was last modified: 03-01-2018, 03:17 PM by Germanikus.)

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.
Reply
#2

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');
 
       }
 
   


What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB