Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
$code=$_REQUEST['code']; 
$sql1="SELECT * FROM inventory WHERE code='$code' and available_quantity ='0'";
$result1 = mysqli_query($conn, $sql1);
    if(mysqli_num_rows($result1) < 1){
      echo "<button type='submit' name='submit'>Submit</button>"; 
}else{echo "<h5>Asset Quantity Exceeds Limit</h5>";}


What I have tried:

<blockquote class="quote"><div class="op">Quote:</div>hey guys can you please help me convert this native php code to codeigniter 3.
</blockquote>
Posted
Updated 8-Mar-23 8:57am
Comments
Richard MacCutchan 8-Mar-23 14:34pm    
You deconstruct the PHP and rewrite it in codeigniter.

1 solution

ChatGPT?

Question
can you convert this php code into codeigniter
PHP
$code=$_REQUEST['code']; 
$sql1="SELECT * FROM inventory WHERE code='$code' and available_quantity ='0'";
$result1 = mysqli_query($conn, $sql1);
    if(mysqli_num_rows($result1) < 1){
      echo "<button type='submit' name='submit'>Submit</button>"; 
}else{echo "<h5>Asset Quantity Exceeds Limit</h5>";}


Answer
Sure! Here's the CodeIgniter equivalent of the given PHP code:
PHP
$code = $this->input->post('code');
$this->db->where('code', $code);
$this->db->where('available_quantity', 0);
$result = $this->db->get('inventory');

if ($result->num_rows() < 1) {
  echo "<button type='submit' name='submit'>Submit</button>";
} else {
  echo "<h5>Asset Quantity Exceeds Limit</h5>";
}
In this CodeIgniter code, we use the input library to retrieve the code value from the POST request. Then we use CodeIgniter's active record ($this->db) to build and execute the SQL query. The get method returns a result object, which we can use to check the number of rows returned by the query. Finally, we output either a submit button or an error message depending on the number of rows returned.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900