Codeigniter बैच चेकबॉक्स के लिए अद्यतन

Nov 02 2020

मेरे पास इस तरह की स्थिति है, मैं कुछ डेटा को अपडेट करना चाहता हूं जहां इनपुट चेकबॉक्स हैं, मुझे नीचे इस कोड की कोशिश की गई थी। डेटा पहले से ही डेटाबेस में सहेजा गया है, लेकिन किसी अन्य पंक्ति में डेटा सहेजा गया है,

उदाहरण के लिए: मैंने बर्डए के लिए रंग लाल, पीला और ग्रे की जांच की और मैंने उसी समय बर्डड के लिए गहरे और नीले रंग की जांच की। डेटाबेस में, बर्डा के लिए रंग सही ढंग से सहेजा गया है, लेकिन बर्ड के लिए डार्क बर्ड और डार्क बर्ड को बचाया जाना चाहिए (बर्ड को बचाना चाहिए )

मैं अपनी समस्या को ऊपर हल करना चाहता हूं, इसलिए डेटा को डेटाबेस में सही जगह पर सहेजा जाना चाहिए। कृपया नीचे मेरा कोड जांचें:

मेरी डीबी तालिका:

=============================================
| birds | red | blue | grey | yellow | dark | 
=============================================
| BirdA |  0  |   0  |   0  |   0    |   0  |
| BirdB |  0  |   0  |   0  |   0    |   0  |
| BirdC |  0  |   0  |   0  |   0    |   0  |
| BirdD |  0  |   0  |   0  |   0    |   0  |
=============================================

राय :

  <tr>
    <td><input type="hidden" name="birds[]" value='<?php echo $dp['birds']; ?>' /><?php echo $dp['birds']; ?></td>
    <td><p align='center'><input type="text" name="qtt[]" value='<?php echo $dp['qtt']; ?>' tabindex="2" style="width:30px;" /></td> <td><p align='center'><input type="checkbox" name="red[]" value='1' <?php if($dp['red']==1) { echo " checked=\"checked\""; } ?> /></td>
    <td><p align='center'><input type="checkbox" name="blue[]" value='1' <?php if($dp['blue']==1) { echo " checked=\"checked\""; } ?> /></td> <td><p align='center'><input type="checkbox" name="grey[]" value='1' <?php if($dp['grey']==1) { echo " checked=\"checked\""; } ?> /></td>
    <td><p align='center'><input type="checkbox" name="yellow[]" value='1' <?php if($dp['yellow']==1) { echo " checked=\"checked\""; } ?> /></td> <td><p align='center'><input type="checkbox" name="dark[]" value='1' <?php if($dp['dark']==1) { echo " checked=\"checked\""; } ?> /></td>
  </tr>

और नियंत्रक:

    $birds= $this->input->post("birds");
        if (empty($this->input->post("birds"))){ $birds= 0;
        }
    $qtt= $this->input->post("qtt");
        if (empty($this->input->post("qtt"))){ $qtt= 0;
        }
    $red= $this->input->post("red");
        if (empty($this->input->post("red"))){ $red= 0;
        }
    $blue= $this->input->post("blue");
        if (empty($this->input->post("blue"))){ $blue= 0;
        }
    $grey= $this->input->post("grey");
        if (empty($this->input->post("grey"))){ $grey= 0;
        }
    $yellow= $this->input->post("yellow");
        if (empty($this->input->post("yellow"))){ $yellow= 0;
        }
    $dark= $this->input->post("dark");
        if (empty($this->input->post("dark"))){ $dark= 0;
        }

    for($x = 0; $x < sizeof($birds); $x++){
        $reslt[$x] = array(
            "birds"    => $birds[$x],
            "qtt"  => $qtt[$x],
            "red"  => $red[$x],
            "blue"  => $blue[$x],
            "grey"  => $grey[$x],
            "yellow"  => $yellow[$x],
            "dark"  => $dark[$x]
            );
        }
        $this->db->update_batch('db_birds', $reslt, 'birds');

उस कोड को निष्पादित करने के बाद, php में एक त्रुटि है:

A PHP Error was encountered
Severity: Notice

Message: Undefined variable: x

Filename: controllers/....

Line Number: 613

Backtrace:

File: /home/.....
Line: 613
Function: _error_handler

File: /home/..../index.php
Line: 315
Function: require_once

A PHP Error was encountered
Severity: Notice

Message: Undefined offset: 3

Filename: controllers/....

Line Number: 621

Backtrace:

File: /home/....
Line: 621
Function: _error_handler

File: /home/..../index.php
Line: 315
Function: require_once

A PHP Error was encountered
Severity: Notice

Message: Undefined offset: 3

Filename: controllers/...

Line Number: 622

Backtrace:

File: /home/...
Line: 622
Function: _error_handler

File: /home/.../index.php
Line: 315
Function: require_once

A PHP Error was encountered
Severity: Notice

Message: Undefined offset: 4

Filename: controllers/...

Line Number: 620

Backtrace:

File: /home/...
Line: 620
Function: _error_handler

File: /home/.../index.php
Line: 315
Function: require_once

A PHP Error was encountered
Severity: Notice

Message: Undefined offset: 4

Filename: controllers/...

Line Number: 621

Backtrace:

File: /home/...
Line: 621
Function: _error_handler

File: /home/.../index.php
Line: 315
Function: require_once

A PHP Error was encountered
Severity: Notice

Message: Undefined offset: 4

Filename: controllers/...

Line Number: 622

Backtrace:

File: /home/...
Line: 622
Function: _error_handler

File: /home/.../index.php
Line: 315
Function: require_once

A PHP Error was encountered
Severity: Notice

Message: Undefined offset: 5

Filename: controllers/...

Line Number: 618

Backtrace:

File: /home/...
Line: 618
Function: _error_handler

File: /home/.../index.php
Line: 315
Function: require_once

......

धन्यवाद शुभकामनाएं

जवाब

1 KUMAR Nov 03 2020 at 00:33

नियंत्रक कोड: -

for($x = 0; $x < sizeof($birds); $x++){
        $reslt[$x] = array(
            "birds"    => $birds[$x],
            "qtt"  => $qtt[$x],
            "red"  => $red[$x],
            "blue"  => $blue[$x],
            "grey"  => $grey[$x],
            "yellow"  => $yellow[$x],
            "dark"  => $dark[$x]
            );
        }
$this->db->update_batch('db_birds', $reslt, 'birds');

परिवर्तन आपके दृश्य कोड में है: -

 <?php


//sql Query.
//execute Query.


$ii=0; foreach($dps as $dp){ $iii = $ii++; <tr> <td><input type="hidden" name="birds[<?php echo $iii;?>]" value='<?php echo $dp['birds']; ?>' /><?php echo $dp['birds']; ?></td>
    <td><p align='center'><input type="text" name="qtt[]" value='<?php echo $dp['qtt']; ?>' tabindex="2" style="width:30px;" /></td> <td><p align='center'><input type="checkbox" name="red[<?php echo $iii;?>]" value='1' <?php if($dp['red']==1) { echo " checked=\"checked\""; } ?> /></td> <td><p align='center'><input type="checkbox" name="blue[<?php echo $iii;?>]" value='1' <?php if($dp['blue']==1) { echo " checked=\"checked\""; } ?> /></td> <td><p align='center'><input type="checkbox" name="grey[<?php echo $iii;?>]" value='1' <?php if($dp['grey']==1) { echo " checked=\"checked\""; } ?> /></td> <td><p align='center'><input type="checkbox" name="yellow[<?php echo $iii;?>]" value='1' <?php if($dp['yellow']==1) { echo " checked=\"checked\""; } ?> /></td> <td><p align='center'><input type="checkbox" name="dark[<?php echo $iii;?>]" value='1' <?php if($dp['dark']==1) { echo " checked=\"checked\""; } ?> /></td>
  </tr>
  }
  
  
?>