Forums

How to use db_save data?

Chacapamac 08 Jun, 2011
How can you use the data save in the table in a usefull matter...

1— Can you export to a csv file multiple entry?

In my case my first form with Chrono is a Joomla registration with few custom fields. I want to be able from time to time to bring all that data in a CSV to be able to classified users. When classified I want to create lists based on that classification in a mailing component (Acymailing)... Maybe it’s a easier way to bring those user in acymailing??????


2— Can you send some data to another Joomla table?
My question here is: Can I bring some of the information from that chrono db table to interact with another table in joomla.

Just to bring me on the right path...
GreyHead 09 Jun, 2011
Hi Chacapamac,

1) I have a CSV Export action here that will let you export a filtered set of columns/records from any table.

2) I'm not suer what you want to do in (2) but you can do most kinds of data manipulation if you know enough MySQL.

Bob
lowrykun 09 Aug, 2011
I saw this post and thought I'd share an easy solution for acymailing that I did.

I had a simple Squeezebox that collects basic information (Name, Email, Country, and a Newsletter Checkbox). You'll need to have at least name and email and edit the code as required. The $listid is the ID of the newsletter that you want to subscribe them to.

Other suggestions are welcome. For example, you may want to check #__acymailing_subscriber to see if the email is already there. If it is, then you don't need the first call, only the second call.

Add a new Custom Code function with something like the following:

<?php
$email = $form->data['email'];
$name = $form->data['contact_name'];
$newsletter = $form->data['newsletter'];
$time = time();
$listid = 1;

if($newsletter == 1){

  $db =& JFactory::getDBO();
  $query = "insert into #__acymailing_subscriber (email,name,created,confirmed,enabled,accept) values (".$db->quote($email) .",". $db->quote($name) . ",".$db->quote($time).",1,1,1)";
  $db->setQuery($query);
  $result = $db->query();
  unset($db);

  $db =& JFactory::getDBO();
  $query = "insert into #__acymailing_listsub (listid, subdate, subid, status)
values ($listid,$time,(select subid from #__acymailing_subscriber where email=".$db->quote($email)." order by subid desc limit 1),1)";
  $db->setQuery($query);
  $result = $db->query();
}
?>
lowrykun 09 Aug, 2011
Here's an update that prevents the email address from being added to the database twice, then prevents the user from being added to the same list multiple times.

<?php
$email = $form->data['email'];
$name = $form->data['contact_name'];
$newsletter = $form->data['newsletter'];
$time = time();
$listid = 1;

if($newsletter == 1){
  $db =& JFactory::getDBO();
  $query="select email from #__acymailing_subscriber where email=".$db->quote($email);
  $db->setQuery($query);
  $db->query();
  $num_rows = $db->getNumRows();
  unset($db);

  if ($num_rows == 0) {
    $db =& JFactory::getDBO();
    $query = "insert into #__acymailing_subscriber (email,name,created,confirmed,enabled,accept) values (".$db->quote($email).",".$db->quote($name).",".$db->quote($time).",1,1,1)";
    $db->setQuery($query);
    $result = $db->query();
    unset($db);
    unset($num_rows);
  }

  $db =& JFactory::getDBO();
  $query="select subid from #__acymailing_listsub 
 where subid=(select subid from #__acymailing_subscriber where email=".$db->quote($email).") and listid=$listid";
  $db->setQuery($query);
  $db->query();
  $num_rows = $db->getNumRows();
  unset($db);

  if ($num_rows == 0) {
    $db =& JFactory::getDBO();
    $query = "insert into #__acymailing_listsub (listid, subdate, subid, status)
values ($listid,$time,(select subid from #__acymailing_subscriber where email=".$db->quote($email)."),1)";
    $db->setQuery($query);
    $result = $db->query();
  }
}

?>
This topic is locked and no more replies can be posted.