CodeIgniter Forums

Full Version: Codeigniter check if values exist with database
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum


I want to compare values with what's in the database.

This is my database the table name is coordinates

Id xone xtwo yone ytwo
1 519 819 64 364
2 820 920 40 140
This is my html, values are dynamically generated in here.. But for the purpose of this question ill put some values..

<input type="button" id="dsubmit" value="button"/>
<span id="status" class="status" name="status"></span>
<span id="finalX" >500</span>
<span id="finalXm">600</span>
<span id="finalY" >80</span>
<span id="finalYm" >280</span></center>

Im sending the values in this span to my controller using ajax but no worries about the ajax because im sure it works as i've tested it extremly..

Then this is my controller function. I'm basically cheeking if the value of in the span which is the coordinate of a box overlaps with the value of the boxes already in the database.

public function coord_check() {

$X = $this->input->post('finalX');
$Xm = $this->input->post('finalXm');
$Y = $this->input->post('finalY');
$Ym = $this->input->post('finalYm');

$query = $this->db->where('Id >',0)->get('coordinates');
foreach($query->result() as $row) {

if( $row->xone >= $X && $row->xone <= $Xm)
{echo "xerror";}

elseif( $row->xtwo >= $X && $row->xtwo <= $Xm)
{echo "xerror";}

elseif ($row->xone > $Xm || $row->xtwo < $X) {
echo "noerror";
else {
echo "noerror";
The code atm echo's noerror for values that even match that in the database. Can anyone see where my mistake is? Many Thanks..