[SOLVED] Form Plugin PHP | if else loop | 2 different mysql queries + Solution

marcq

Member
Hi,

First time I'm trying to do this.

I would like to generate with a if elseif loop 2 different queries according the value of a radio button :

If value == 1 -> generate query one
Else value == 0 -> generate query two

I have tried the following, but without success :

Code:
// Get the logged in Userid
$user = JFactory::getUser();
$userid = $user->get('id');
// var_dump($userid);exit;

// Get the row Id
$rowid = $formModel->formData['id'];
// var_dump($rowid);exit;

// Know of user enrolled or not
$join = $formModel->formData['integration_equ'];
// var_dump($join);exit;

// Insert or update the "fab_inscriptioneve_repeat_membre" table
if ($join==1)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = "INSERT INTO fab_inscriptioneve_repeat_membre (parent_id,membre) VALUES ('$rowid','$userid')";
$db->setQuery($query);
$crewjoin=$db->execute();
} else ($join==0) { 
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = "DELETE FROM fab_inscriptioneve_repeat_membre WHERE membre='$userid'";
$db->setQuery($query);
$crewquit=$db->execute();

I guess I have a missbuilding here, I get the values of the fields I need, but no data is naturaly saved in the database field.

Would appreciate some support here. Thank you in advance. Cheers, marc
 
Do those var_dumps output what you are expecting, with the correct $rowid and $join?

What hook are you running this one (onBeforeProcess, onAfterProcess)?

-- hugh
 
Do those var_dumps output what you are expecting, with the correct $rowid and $join?

What hook are you running this one (onBeforeProcess, onAfterProcess)?

-- hugh
Hi Hugh,
Thank you for your reply. Yes the var_dumps output are ok. I would like to run it onAfterProcess.
Cheers, marc
 
OK, so dump $query before executing it, see what that looks like.

BTW, I presume you do actually have a closing } on the end?

-- hugh
 
Hi Hugh,
Thank you for your reply. I found the problem. The following query is now working :

Code:
// Get access to the database
$db = JFactory::getDbo();

// Get the logged in Userid
$user = JFactory::getUser();
$userid = $user->get('id');

// Get the row Id
$rowid = $formModel->formData['id'];

// Get the status of enrollment : 0 = didn't enroll, 1 = enrolled
$join = $formModel->formData['integration_equ'];

// var_dump the values
// var_dump($userid,$rowid,$join);exit;

// Run the queries to insert or delete the crew member from the "fab_inscriptioneve_repeat_membre" table
if ($join==1)
{ 
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = "INSERT INTO fab_inscriptioneve_repeat_membre (parent_id,membre) VALUES ('$rowid','$userid')";
$db->setQuery($query);
$crewjoin=$db->execute();
} elseif ($join==0) { 
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = "DELETE FROM fab_inscriptioneve_repeat_membre WHERE membre='$userid'";
$db->setQuery($query);
$crewjoin=$db->execute(); 
}
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top