MySQL: How to update a field only if condition is true

MySQL:  update a field only if condition is true.Update a field only if condition is true in query

Using IF statement we can do this
For example :- If i want to update user level if user score is 500+
and if user join time in 24 hour

We can add multiple condtion in IF statement

UPDATE table SET level = IF(score > 500 AND  jointime (HOUR, jointime , ‘2018-06-27 16:27:54’) > 24 , USERNEWLEVEL , level) WHERE user_id = 5

How to get single row data in CI

Result Rows

Row() returns a single result row data.  If query has more than one row, it returns only the first row of data. The result is returned as an object. Example:-

$query = $this->db->query(“YOUR QUERY”);

$row = $query->row();

if (isset($row))
{
echo $row->title;
echo $row->name;
}
If you want data in array format use row_array()
Example:

$query = $this->db->query(“YOUR QUERY”);

$row = $query->row_array();

if (isset($row))
{
echo $row[‘title’];
echo $row[‘name’];
echo $row[‘body’];
}

Generating Query Results as Row in CI

What is difference between result and result_array in CI

if we use result()  to get results it will returns  the query result as an array of objects
$query = $this->db->query(“YOUR QUERY”);

foreach ($query->result() as $row)
{
echo $row->title;
echo $row->name;
echo $row->body;
}

if we use result_array()  to get result as a pure array
$query = $this->db->query(“YOUR QUERY”);

foreach ($query->result_array() as $row)
{
echo $row[‘title’];
echo $row[‘name’];
echo $row[‘body’];
}

 
Generating Query Results in CI

How to check URL is valid or not in PHP?

URL validation in php

Sort Multi-dimensional Array by Value

Sort Multi-dimensional Array by Value
Above or PHP 5.3

Change or replace the href of an anchor tag with javascript

With help of java script you can change href of any anchor tag.