title: getting the value of column inside a table using ajax in php codeigniter
body: <p>I have a simple shopping website in codeigniter in which I have an sql table like below:</p>
  <p><a href="https://i.stack.imgur.com/xywf8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xywf8.png" alt="enter image description here" /></a></p>
  <p>So whenever a user selects a product size, I want to show how many pieces are left, so I took the following approach for this code:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function checkstock() {
  
    var stockid = $(".stockid").val();
    var idp = $("#idp").val();
    var transfer = [stockid, idp];
    $.ajax({
      type: "post",
      url: "&lt;?php echo base_url(); ?&gt;index.php/homecontroller/checkstock",
      data: {
        result: JSON.stringify(transfer)
      },
      success: function(response) {
        if (response) {
          $('#msg').html('&lt;span style="color: green;"&gt;ONLY ' + stockid + "&lt;/span&gt;");
  
        }
      }
    });
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input id="idp" name="prodid" value="&lt;?php echo $product-&gt;id;?&gt;" type="hidden"&gt;
  &lt;input class="stockid" type="radio" onclick="checkstock();" name="size" value="xs"&gt;
  &lt;input class="stockid" type="radio" onclick="checkstock();" name="size" value="s"&gt;
  &lt;input class="stockid" type="radio" onclick="checkstock();" name="size" value="m"&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>Below is my controller's and view's code,</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  function checkstock(){
            $post = json_decode($_POST['result']);
            $idp = $post[1];
            $stockid = $post[0];
            $exists = $this-&gt;product-&gt;checkstock($idp,$exists);
            echo $exists;
    }</code></pre>
  </div>
  </div>
  </p>
  <pre><code><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  function checkstock($idp,$stockid)
     {
          $this-&gt;db-&gt;select($stockid);
          $this-&gt;db-&gt;where('id', $idp);
          $this-&gt;db-&gt;from('product');
          $query = $this-&gt;db-&gt;get();
          $result = $query-&gt;result();
          return $result;
     }
  
    </code></pre>
  </div>
  </div>
  
  </code></pre>
  <p>However this doesn't echo the count in the column, can anyone please tell me how to fix this, thanks in advance.</p>