13 Posts
wisesiteguy
10 years ago
2
Topic

Hi Sebloders. I'm hoping I can get a little help/advce.

What I'm trying to do... 

I'm building a site function where users complete an assessment form which assigns them to a 'satisfaction_group' (low=3, moderate=4, high=5) - this I've been able to achieve successfully. 

Now, when the user submits the assessment form, I want to also update the users subscription to an acymailing newsletter list based on the satisfaction_group they're assigned to - low = listid 3, moderate = listid 4, high = listid 5. 

My users are all subscribed to the moderate list on registration, so acymailing knows they exist with id values setup, etc. Users will be subscribed to one mailing list only. Just fyi, acymailing creates a subscriber id (subid) matched to each joomla userid. 

I thought I would be able to do this with a 42 field, using the following code in 'PrepareStore'... 

// assign to satisfaction group based on their score 

$total = $config['post']['total_satisfaction'];

if ($total >= 3 && $total <=9) $value = 3;

if ($total >= 10 && $total <=16) $value = 4;

if ($total >= 17 && $total <=21) $value = 5; 

//this $value gets saved in the db in a seperate table along with the all the scores etc. - this works all good

$userid = $config['post']['satisfaction_user_id']; // this is obtained using a 'live' value - perhaps it's better to get it from user->id?? 

// now query the database to get the subscriber_id for the logged in user from acymailing 

$db = JFactory::getDbo(); 

$query1 = $db->getQuery(true); 

$query1->select('subid'); 

$query1->from('#__acymailing_subscriber'); 

$query1->where('id='.$userid); 

$db->setQuery($query1); 

$subid = $db->loadResult();

//then update the acymailing subscription to reflect the satisfaction group 

$sql = "UPDATE `#__acymailing_listsub` SET listid=".$value." WHERE subid=".$subid."; 

$db->setQuery($sql); 

$db->query(); 

The code is not throwing any errors on save, the $value and other scores is saved to its table, but the acymailing listid is not being updated. I'm a php and seblod novice, and an sql noob, so I'm probably going about this the wrong way, so any help/suggestions would be appreciated. 

Thanks in advance

Andrew

Get a Book for SEBLOD
13 Posts
wisesiteguy
10 years ago
1
Level 1

Looks like I am able to answer my own question...

$query1->where('id='.$userid); should read $query1->where('userid='.$userid);

and the UPDATE statement needed the quotes closed.

And now is working! Onward!

Thanks friends

1283 Posts
Bucklash
8 years ago
0
Level 2

+1

Get a VIP membership