Stopping a database entry based on IF NULL! Topic is solved

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
User avatar
donnan
Joomla! Ace
Joomla! Ace
Posts: 1494
Joined: Sat Jun 30, 2007 1:23 am
Location: Sydney, Australia
Contact:

Stopping a database entry based on IF NULL!

Post by donnan » Tue Jul 24, 2018 2:41 am

Hi guys,

I am trying to stop 2 tables from being updated based on an update on the first table.

Here is what I have:

Code: Select all

//add user to pif_table//
$query = $db->getQuery(true);
$query="UPDATE `pif_table` SET $g = '$uname', @success = 1 WHERE $g IS NULL OR $g = '' AND id = '$id' ";
$db->setQuery($query);
$result = $db->execute();
So, the first table, above is updated only if the $g column is empty.

I only wish the next 2 tables to be updated IF, $g column was empty and was updated above.

I receive a syntax error from the @success = 1 part of the command.

Code: Select all

if ($success == 1){
$query = $db->getQuery(true);
$query="UPDATE `jospk_users` SET tables = tables +1, payments = payments +1, tbl".$pifbase."= tbl".$pifbase." +1 WHERE id = '$uid'";
$db->setQuery($query);
$result = $db->execute();


$query = $db->getQuery(true);
$query = "INSERT INTO `pif_payments` (`table_num`, `r_1`, `r_2`, `r_3`, `r_4`, $g, `amount`) VALUES ('$id', '$r1', '$r2', '$r3', '$r4', '$uname', '$pifbase') ON DUPLICATE KEY UPDATE $g = '$uname'";
$db->setQuery($query);
$result = $db->execute();
}
Your help is most appreciated.

User avatar
donnan
Joomla! Ace
Joomla! Ace
Posts: 1494
Joined: Sat Jun 30, 2007 1:23 am
Location: Sydney, Australia
Contact:

Re: Stopping a database entry based on IF NULL!

Post by donnan » Fri Jul 27, 2018 10:47 pm

this must be a hard one to come up with an answer. Still waiting patiently!

:pop

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30890
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Stopping a database entry based on IF NULL!

Post by Per Yngve Berg » Sat Jul 28, 2018 9:12 am

Code: Select all

.$pifbase." +1 WHERE id = '$uid'";
+1 is inside the string.

Code: Select all

.$pifbase+1." WHERE id =".$uid.";"
Is $uid a number?

User avatar
donnan
Joomla! Ace
Joomla! Ace
Posts: 1494
Joined: Sat Jun 30, 2007 1:23 am
Location: Sydney, Australia
Contact:

Re: Stopping a database entry based on IF NULL!

Post by donnan » Sat Jul 28, 2018 10:03 am

Hi Per,

thanks for replying. Much appreciated.

Yes, $uid is a number.

User avatar
donnan
Joomla! Ace
Joomla! Ace
Posts: 1494
Joined: Sat Jun 30, 2007 1:23 am
Location: Sydney, Australia
Contact:

Re: Stopping a database entry based on IF NULL!

Post by donnan » Sat Jul 28, 2018 10:12 am

this is where the problem lies.

Code: Select all

$query = $db->getQuery(true);
$query="UPDATE `pif_table` SET $g = '$uname' WHERE $g IS NULL OR $g = '' AND id = '$id' ";
$db->setQuery($query);
$result = $db->execute();
How can I get either a 'true or a false' or a 1 or a 0 if the UPDATE was carried out?

$result returns 1, even if the UPDATE was or wasn't done.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30890
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Stopping a database entry based on IF NULL!

Post by Per Yngve Berg » Sat Jul 28, 2018 11:22 am

$result will be false only when the query fails, not if the where clause does not returns any rows.

I would have used a trigger routine in the database that fires for each row updated, rather than php.

https://dev.mysql.com/doc/refman/5.6/en ... views.html

User avatar
donnan
Joomla! Ace
Joomla! Ace
Posts: 1494
Joined: Sat Jun 30, 2007 1:23 am
Location: Sydney, Australia
Contact:

SOLVED - Re: Stopping a database entry based on IF NULL!

Post by donnan » Sat Jul 28, 2018 8:57 pm

SOLVED -

Ended up writing a SELECT statement to check to see if the field was empty first, then if, yes UPDATE.

:pop


Locked

Return to “Joomla! 3.x Coding”