setQuery($query);$db->query();  and it work right.But if I add thisif(mysql_affected_rows() => 1){ echo 'OK';}else { echo 'NO!';}it don't work.Everyone can help me?Thanks"> mysql_affected_rows() don't work - Forums

Forums

mysql_affected_rows() don't work

pierpari 23 Feb, 2014
Hi,
I have this problem:
My custom code is


$db =& JFactory::getDBO();
$query = "UPDATE `MY_TABLE` SET `MY_FIELD` = 'Si' WHERE `MY_TABLE`.`FIELD` = '$VAR'";
$db->setQuery($query);
$db->query();  



and it work right.
But if I add this

if(mysql_affected_rows() => 1)
{
 echo 'OK';
}
else
 {
  echo 'NO!';
}


it don't work.

Everyone can help me?

Thanks
GreyHead 23 Feb, 2014
Hi pierpari,

You need to check the Joomla! code and check the value from the $db object. It's probably something like $db->numRows() but I'm far from certain about that.

Bob
pierpari 23 Feb, 2014
I find and try this:
$db->affectedRows();
but don't' work. The problem is that if i add everything to the first code it don't update.
Do you understand?
This work
$db =& JFactory::getDBO();
$query = "UPDATE `MY_TABLE` SET `MY_FIELD` = 'Si' WHERE `MY_TABLE`.`FIELD` = '$VAR'";
$db->setQuery($query);
$db->query();  

If I add just this, it don't work (don't print "OK" and don't update table
echo "OK";

Why?
pierpari 24 Feb, 2014
Answer
I have solved.
I write First code into PHP tag, then I open a new PHP tag and write second code (echo "OK";).
Strange but it work
This topic is locked and no more replies can be posted.