Forums

How to add a Search to a Connectivity form!

benblee 17 Mar, 2009
* please note any edits to this post here if you're a mod.
Thanks to Max and Greyhead for all the help on the code. I'm just relaying their notes 😀 !

This is based on the example database set up from this How-To tutorial:
Forms and Connectivity Example start to finish!

In your Joomla backend, go to:
Components -> Chrono Connectivity -> Connections Management

Choose your form.

Under the General tab put this code in these text boxes:
Where SQL:
<?php
$search_array = array('firstname', 'lastname', 'scrnum'); 
$where = array();
foreach ( $search_array as $search ) {
  $value = JRequest::getVar($search, '' , 'post');
  if ( $value ) {
    $where[] = " $search LIKE '$value%' ";
  }
}
if ( !empty($where) ) {
  echo " WHERE ".implode(' AND ', $where);
}?>



The following Header code goes above what you already have there.
Header:
<div style="float:right">
Search for a <b>last name</b>: <input type="text" name="lastname">
 <b>first name</b>: <input type="text" name="firstname">
 <b>number</b>: <input type="text" name="scrnum">
<input type="submit" value="Search" name="undefined" style='width:80px; color:#cccccc; background-color:#222222; cursor:pointer;' /></div>



Some notes:
* This code is VERY touchy to spaces, quotes, and set up. Make sure you are using it just as it is used here.
* You need to substitute the dabase column names with your column names. The names used here are firstname, lastname, scrnum. Change these to yours in all instances above.
* In the Header code, I have the div style attribute of "float:right" because I wanted it to the right on my page, buy you can leave this out or put left in there to have it left aligned.
* The Header code above worked best for me at the top of my other header code.
* This line of code:
<input type="submit" value="Search" name="undefined" style='width:80px; color:#cccccc; background-color:#222222; cursor:pointer;'

defines how the search button looks. change the value="Search" to whatever word you want to show up there and then you can change the hex colors to fit your template. Also change the width to suit your needs. The cursor:pointer makes sure that your cursor changes to a hand symbolizing a link on the page instead of just remaining as an arrow in some browsers.
GreyHead 17 Mar, 2009
Hi Benblee,

Another great tutorial, thank you.

Bob
soliver 18 Mar, 2009
Hi Everyone,
I have completed both tutorials and have learned very much about CF and CC.

What I would love to do, and I am not sure how to accomplish it is to remove the search code from CC and add it to a custom HTML Joomla module so that I can have my search fields in a left side module. I looked into the module that comes with CF but that puts the entire form into the module and has no effect on CC.

Any ideas on how to accomplish this??

Thanks in advance....
hel-G 15 Apr, 2009
Hi!

I have another question: Is it possible for me to show chronoform data only when a relevant search is made?

As of the moment, the search portion is above the table displaying all the chronoform data. I need the table area to be blank until the user does a search and gets relevant results. And then if no relevant data is found a short message is displayed to inform him/her that no data is found and that he/she has to do a search again.

Is this possible? If it is, may I ask for your help on how to go about it? The short message is optional if it is not doable..

Thanks again in advance for your very kind and generous help! God bless you!

Tiffany
hel-G 16 Apr, 2009
Hi!

How come my Search stopped working?

I did make some changes to the column names, some layout and design stuff but not the code itself.. It worked for a while with only the first box getting some relevant results. The other two boxes when used return nothing even when using words that are available in the database table I'm searching from. I switched back to the actual codes given by benblee and yet no search result is given.. What could be the cause? and What can I do to rectify this?

Any response would greatly help me.. Thank you very much!!

Tiffany
GreyHead 16 Apr, 2009
Hi Tiffany,

I've no the slightest idea - most likely some column names don't match up any more . . .

Bob
jeff2 18 Jun, 2009
Hi all,

I have used this post to add search functionality to the form. I have only two array's to search on. The first one never returns any results and the second only returns results if the search text is exactly as written in the table.

I.e The table text is for example WEALMORE PROJECT
If I enter project or PROJECT I get no results but WEALMORE PROJECT returns the row.

Also since adding this search code the {pagination} value is defaulted to 5 when I have made no changes to the original default of 250.

Any help please

Jeff2
Max_admin 18 Jun, 2009
Hi Jeff,

show us your code please!

maybe you need to change
$where[] = " $search LIKE '$value%' ";
to
$where[] = " $search LIKE '%$value%' ";


Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
jeff2 19 Jun, 2009
Hello Admin,

Here is the code I am using for the search function in CC

SQL Box
<?php
$search_array = array('FIELD_208', 'FIELD_151'); 
$where = array();
foreach ( $search_array as $search ) {
  $value = JRequest::getVar($search, '' , 'post');
  if ( $value ) {
    $where[] = " $search LIKE '%$value%' ";
  }
}
if ( !empty($where) ) {
  echo " WHERE ".implode(' AND ', $where);
}?>

Header box;
<div>
Search for a <b>Project</b>: <input type="text" name="FIELD_151">
added by <b>Name</b>: <input type="text" name="FIELD_208">
<input type="submit" value="Search" name="undefined" style='width:80px; color:#cccccc; background-color:#222222; cursor:pointer;' /></div>
<br />
<?php
$i = 0;
?>
<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="0">
  <tbody>
    <tr style="background-color: rgb(204, 204, 204)";>
      <td style="font-weight: bold; width: 5%;">Form No</td>
      <td style="font-weight: bold; width: 12%;">Ref. No</td>
      <td style="font-weight: bold; width: 15%;">Added by</td>
      <td style="font-weight: bold; width: 10%;">Value £</td>
      <td style="font-weight: bold; width: 8%;">Status</td>
      <td style="font-weight: bold; width: 50%;">Project Title</td>
    </tr>
  </tbody>
</table>

Body box
<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="0">
  <tbody>
<tr<?php if ($i % 2) echo ' style="background-color: #EBEBEB;"';?>>
      <td style="font-weight: bold; color: gray; width: 5%;">{id}</td>
      <td style="font-weight: bold; color: #000000; width: 12%;">{FIELD_189}</td>
      <td style="font-weight: bold; color: gray;width: 15%;">{FIELD_208}</td>
      <td style="font-weight: bold; color: gray;width: 10%;">{FIELD_210}</td>
      <td style="font-weight: bold; color: gray;width: 8%;">{FIELD_154}</td>
      <td style="font-weight: bold; color: blue;width: 50%;">{FIELD_151}</td>
    </tr>
  </tbody>
</table>
<?php $i++ ?>

Footer box
<div class="clr" style="border-bottom: 2px solid #222; padding: 3px; margin-bottom: 10px;"></div>
    <script type="text/javascript">
    window.addEvent('domready', function() {
       var limit_select = $('limit').options;
       if ( !limit_select ) return;
       for ( var i = 0; i < limit_select.length; i++ ) {
            if ( limit_select[i].value == 0 ) {
               limit_select[i].value = 100;
               limit_select[i].innerHTML = '250';
            }
       }
    });
    </script>
<div align="center">{pagination}</div>

Many thanks jeff2
jeff2 19 Jun, 2009
Hi Admin,

I do not know much about SQL scripts, but in the following line

$where[] = " $search LIKE '%$value%' ";

the search is for something LIKE

Does this not infer that it is searching for a string exactly the same in the field ?

Is there a function to search for lower case, upper case or both etc.

The LIKE may do this but this is just a question.

jeff2
GreyHead 19 Jun, 2009
Hi jeff2,

Probably best to check the MySQL docs as this isn't ChronoForms syntax. '%' is a wild card in a LIKE statement so LIKE 'XYZ%' will find values starting with XYZ, LIKE '%XYZ' will find values ending in XYZ and LIKE '%XYZ%' will find values containing XYZ.

LIKE is case insensitive unless you specify a binary string for one of the values. There ae other MySQL functions that can work with case.


Bob
jeff2 19 Jun, 2009
Hi Bob,

Thanks for that, this is what makes it so strange, any word in the the text string I am searching for has to match exactly that in the table field, i will have to check in mysql if there are ways of converting all text using GET to lower case (if this is possible) and then search this.

jeff2
GreyHead 19 Jun, 2009
Hi jeff2,

At this point I output the sql query statement and copy and paste it into PHPMyAdmin to see what is actually hapenning.

Bob
jeff2 19 Jun, 2009
Bob,

I have made some searches on this area, and one site shows the following on filtering

// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

I assume reading bewtween the line the above code, changes all text to upper case, removes any tags and removes white space.

If I use strtolower would this change everything to lower case and where would i insert such code ?

jeff2
GreyHead 19 Jun, 2009
Hi jeff2,

Yes it would - but as the LIKE search is case insensitive it probably won't make any difference. Can you tell me a bit more about the problem you are trying to solve?

Bob
. . .
$value = strtolower($value);
$where[] = " $search LIKE '%$value%' ";
jeff2 20 Jun, 2009
Hi Bob,

I think the LIKE shown below should be case insensitive, but in practice in my example this is not true, if I am searching for say School in the field and enter Schoool or Scho it works fine. If i type scho (all lower case) it returns no result. One other drawback is that it is only useful for searching on ONE keyword. has anyone written some code for full text searching ?.

$where[] = " $search LIKE '%$value%' ";

I have got around the problem by cahnging the field data in the database to lower case and putting a note for the user to sesarch with lower case also.

Not the best solution but it works.

Jeff2
GreyHead 20 Jun, 2009
Hi Jeff2,

Glad you've got it working 'well enough'.

You can build much more complex searches - here's 'one I did earlier' that links up five or six different search options into one MySQL search. This includesd full text searches, searches across several fields, searching for multiple values (from a drop-down). Although this wasn't for Chronoconnectivity it returns a array of searches ready to be added to a WHERE string:
    /**
     * Function to build the WHERE phrase for the database query
     *
     * @return string
     */
    function _buildContentWhere()
    {
        if ( !$this->_search ) return false;

        global $mainframe, $option;

        // Initialise the variables & db object
        $db =& JFactory::getDBO();

        $filter_state     = $this->getState('filter_state');
        $filter_order     = $this->getState('filter_order');
        $filter_order_Dir = $this->getState('filter_order_Dir');
        $type_lookup = array(
        	'ar_location' => 'desired_location',
            'or_name' => "first_name, last_name, known_as",
            'ft_experience' => 'emp_posn_1, emp_resp_1, emp_posn_2, emp_resp_2,
            	emp_posn_3, emp_resp_3, emp_posn_4, emp_resp_4',
            'fb_experience' => 'emp_posn_1, emp_resp_1, emp_posn_2, emp_resp_2,
            	emp_posn_3, emp_resp_3, emp_posn_4, emp_resp_4',
            'or_service' => "final_rank, service, branch",
            'or_language' => 'lang_name_1, lang_name_2, lang_name_3, lang_name_4',
            'or_qual' => 'qual_academic, qual_service, qual_civilian',
            'lu_service' => 'service',
            'require' => 'require',
            'cb_driver' => 'driver'
            );
        $return = array();
        // WHERE MATCH ( column list ) AGAINST (Like)
        // WHERE ( column_1 LIKE match OR column_2 LIKE match [OR ...])
        foreach ( $this->_search as $type => $search ) {
            if ( is_array($search ) ) {
                foreach ( $search as $k => $v ) {
                    $search[$k] = JString::strtolower( $v );
                }
            } else {
                $search = JString::strtolower( $search );
            }
            // add search filter
            if ( $search ) {
                switch ( substr($type, 0, 3) ) {
                    case 'ft_':
                        // full text search
                        $like = $db->Quote( $db->getEscaped( $search, true ), false );
                        $return[] = "MATCH ($type_lookup[$type]) AGAINST ($like) ";
                        break;
                    case 'fb_':
                        // full_text boolean search
                        $like = $db->Quote( $db->getEscaped( $search, true ), false );
                        $return[] = "MATCH ($type_lookup[$type]) AGAINST ($like IN BOOLEAN MODE) ";
                        break;
                    case 'or_':
                        // OR search in several fields
                        $temp = array();
                        $like = $db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
                        $types = explode(',', $type_lookup[$type]);
                        foreach ( $types as $v ) {
                            $temp[] = "LOWER($v) LIKE $like ";
                        }
                        $return[] = "( ".implode(' OR ', $temp)." ) ";
                        break;
                    case 'lu_':
                        // Plain value lookup but ignore blank values
                        $like = $db->Quote( $search, false );
                        $needle = $db->nameQuote($type_lookup[$type]);
                        $return[] = $needle." = $like ";
                        break;
                    case 'cb_':
                        //Checkbox lookup
                        $like = $db->Quote( 1, false );
                        $needle = $db->nameQuote($type_lookup[$type]);
                        $return[] = $needle." = $like ";
                        break;
                    case 'ar_':
                        // search for an array of values
                        if ( is_array($search) ) {
                            $temp = array();
                            $needle = $db->nameQuote($type_lookup[$type]);
                            foreach ( $search as $s ) {
                                $s = $db->Quote('%'.$s.'%', false);
                                $temp[] = "LOWER($needle) LIKE $s ";
                            }
                            $return[] = "( ".implode(' OR ', $temp)." ) ";
                        }
                        break;
                    default:
                        // plain search in a single field using LIKE
                        $like = $db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
                        $needle = $db->nameQuote($type_lookup[$type]);
                        $return[] = "LOWER($needle) LIKE $like ";
                        break;
                }
            }
        }
        // echo "where-query: ".print_r($return, true)."<br /><br />";
        return $return;
    }

Bob
benblee 20 Jun, 2009
Great post Bob! Thanks for sharing! 😀 😛 😀

That gives plenty to dig through and plenty of options.
erict 23 Jun, 2009
I thought I might jump in here.

I don't know if any of you noticed but when you make a form a menu item and try and add modules to the page, once you perform a search the modules dissapeer. I figured out a fix for this:

<?php if(JRequest::getVar('Itemid')) { ?>
  <input name="Itemid" type="hidden" value="<?php  echo JRequest::getVar('Itemid'); ?>" />
<?php } ?>


This should make it so you don't lose your modules.
scob888 29 Jun, 2009
Hello,

I'm using the code posted by benblee and I have trouble with it. The search function works perfectly if the total of results is less than one page. For exemple if I have 750 records (30 pages) and the total results of the search function is 15 records (1 page), there is no problem. But if the total of results is 75 records (3 pages), there is a problem. The first page is good, but if I go to the page 2, it is like if I go to the page 2 of all my records. In other words, the first page is 1/3, but if I go to another page, there are 2/30 and 3/40 and it is possible to go to the next pages. How can I fix the problem ?

Thank you for your help

Scob
NiceIce 18 Jul, 2009
Where would an else echo "No Results Found" statement go in the original code posted as the example for this tutorial go?

If no results are found as a result of the query, I'd like to add a statement that indicates that the search was conducted, but that the item searched for is not registered.
GreyHead 19 Jul, 2009
Hi HiceIce,

There was a recent thead where Emmanuel and I both posted solutions to this - I think mine showed the message in the header and his in the footer.

Bob
Kixsian 26 Jul, 2009
Anyway to not have anything shown untill you search?

Thanks
GreyHead 26 Jul, 2009
Hi Kixsian,

I think that you could probably do with conditional WHERE clause - by setting it so that the search will always fail if there is no search term.

Bob
sitebuildernow 19 Aug, 2009

Hi!

I have another question: Is it possible for me to show chronoform data only when a relevant search is made?

As of the moment, the search portion is above the table displaying all the chronoform data. I need the table area to be blank until the user does a search and gets relevant results. And then if no relevant data is found a short message is displayed to inform him/her that no data is found and that he/she has to do a search again.

Is this possible? If it is, may I ask for your help on how to go about it? The short message is optional if it is not doable..

Thanks again in advance for your very kind and generous help! God bless you!

Tiffany



Did you get this answered Tiffany? I would very much like to do this - basically I would like a page that the customer can come to and look up an existing "order" that has a unique order number that only the customer would know - this would call up JUST that record for them to review and edit... any help?
sitebuildernow 19 Aug, 2009

Hi Kixsian,

I think that you could probably do with conditional WHERE clause - by setting it so that the search will always fail if there is no search term.

Bob



Can you provide an example please - I am sorry but I don't know code well enough to write this myself. All of your help is greatly appreciated!
Harmony
maxxoros 31 Aug, 2009
Hi there

Anyone succeeds use this method for searching. I used to use this way for my List, however, with upgrade to CC Rc2 and now Rc3, all my search stop with no reason
sitebuildernow 03 Sep, 2009
Hi Maxxoros,
I have had great success with this thanks to this forum and Max. I hope to post a step by step of how I was able to create a form, have it generate a unique "tracking" code and post to a database then use chronoconnect to allow the customer to come back to our site, use their unique code to search for the data they posted and edit it. Their edit will also generate an email to us that says "this information has been updated" so that we know to deal with the changes. Unfortunately, I am buried right now so I probably can't get my written "this is how I did it" done until, at best, this weekend.
Harmony - SiteBuilder Now
mirkogeo 07 Sep, 2009
Hello,
meanwhile, congratulations and thanks for this good work as ChronoForms and ChronoConnectivity.
My problem is that: I added the search to Connectivity form pages but does not work.
When i click on botton "Cerca" (is Search) nothing appear.
Someone could help me?
I did everything as described in this post but nothing doing.
What can I do?
Thanks.
This is in WHERE SQL:
order by gruppo
    <?php
    $search_array = array('gruppo');
    $where = array();
    foreach ( $search_array as $search ) {
      $value = JRequest::getVar($search, '' , 'post');
      if ( $value ) {
        $where[] = " $search LIKE '$value%' ";
      }
    }
    if ( !empty($where) ) {
      echo " WHERE ".implode(' AND ', $where);
    }?>

and this in the Header:
Database dei gruppi speleologici italiani.<br><hr>
    <div style="float:left">
    Cerca per <b>Gruppo</b>: <input type="text" name="gruppo">
    <input type="submit" value="Cerca" name="undefined" style='width:80px; color:#cccccc; background-color:#222222; cursor:pointer;' /></div><br>
<hr>{new_record}</br></hr>

This is the url page with result form.
http://www.geocaibassano.it/database-gruppi-italiani?start=10
Thank and sorry for my english!

Search now working...only i have set on YES the "Enable Form tags" in General setting.
maxxoros 10 Sep, 2009
Please, could anyone has solution for search, this method has stopped working 😟 😟
mirkogeo 10 Sep, 2009
Hi maxxoros,
try to set on YES the "Enable Form tags" in General setting, for me this is the solution.
GreyHead 17 Sep, 2009
Hi maxxoros,

Did Enabling the Form Tags resolve this problem for you?

Bob
izindaba 28 Sep, 2009
Thanks for this code - it is great.
I have one question - maybe more to do with Chrono Connectivity than PHP.
I'm using PHP code in the body, just experimenting - trying to add totals to a field value - which I will show later.
However, as soon as I convert my variable to numeric, the value of the variable reverts to zero.
This works - the value is stored in $Amt - <?PHP $Amt="{Amount}";?>
Then I say $x = (int)$Amt; - and this works on a if(is_numeric($x)) check. BUT, immediately after that line, I have this: echo "'{$x}' is numeric"; - and it shows the value as 0. If I echo on $Amt BEFORE the (int), then I get the correct value. However, I need to add this up, so therefore need to convert it to numeric.

Is there somewhere I should be declaring / initializing this variable. I've tried different areas, but no joy!

Thanks

Izindaba
GreyHead 28 Sep, 2009
Hi Izindaba,

There was a little thread on this last week. IIRC because of the sequence in which CC works you can't use the {field_name} syntax with PHP in the body section, use $MyRow->field_name instead.

Bob
izindaba 29 Sep, 2009
Hi Greyhead

Thanks for the reply. However, I'm still struggling - and I can't find that post you are referring to.
Based on the Where syntax (below), I am unsure what to use for the $MyRow.
Thanks
Izindaba
<?php
$search_array = array('Party', 'Year', 'Country', 'Sector');
$where = array();
foreach ( $search_array as $search ) {
  $value = JRequest::getVar($search, '' , 'post');
  if ( $value ) {
    $where[] = " $search LIKE '$value%' ";
  }
}
if ( !empty($where) ) {
  echo " WHERE ".implode(' AND ', $where);
}?>
GreyHead 29 Sep, 2009
Hi Izindaba,

A thread using 'MyRow' in the last few days shouldn't be hard to find.

You will not need to change the WHERE clause to count the records, keep a running total in the body, or check the total in the header or footer.

Bob
izindaba 29 Sep, 2009
Thanks Bob - I understand it all now.
Izindaba
maxxoros 14 Oct, 2009
Confirm enable form tag work for me too. It turns out the form tag is set by default disable by CC 😀
jmarian1 25 Nov, 2009
Hi. Thanks for this tutorial. Ut helps a lot. I am beginning to like it. One question though, I noticed that the link is given when you create a new file. What if I decided to include the search form to a page that is already created, is there any way to do it? For example, I have a page working and I want to insert in the bottom of the page the search form I created in Chronoconnectivity, is there anyway to do that? Thanks.
vales 13 Dec, 2009
I made some changes to the scripts for the search with Chronoconnectivity that had been presented in this topic.

Now navigation between pages works. This is the code. I have used for example the table jos_contents

SQL WHERE section
<?php
 $session =& JFactory::getSession('ricerca');
 $search_array = array('title','introtext','fulltext');
 $cerca = array();
 foreach ( $search_array as $search ) {
 $value = JRequest::getVar($search, '' , 'post');
 if ( $value ) {
 $cerca[] = " `$search` LIKE '%$value%' ";
 }
 }
 
 if (empty($cerca) and (JRequest::getVar('submit','no','POST')=="Trova")) {
 $session->set('cerca','0','ricerca');
 JRequest::setVar('limitstart',0,'Get');
 }

 if ( !empty($cerca) ){
 echo " WHERE ".implode(' AND ', $cerca);
 $session->set('cerca',$cerca,'ricerca');          
 }

 elseif ((JRequest::getVar('submit','no','POST')<>"Trova") and  ($session->get('cerca',0,'ricerca')<>0)) {
 $cerca=$session->get('cerca',0,'ricerca');
 echo " WHERE ".implode(' AND ', $cerca);
 }
 else
 {
 echo "";
 }
?>


Section Header
<div style="float:left; width: 100%; ">
<p>    Cerca in <b>Titolo</b>: <input type="text" name="title" />
<b>Introduzione</b>: <input type="text" name="introtext" />
<b>Testo esteso</b>: <input type="text" name="fulltext" /></p)
<p style="text-align:center;"><input type="submit" value="Trova" name="submit" style='width:80px; color:#cccccc; background-color:#135cae; cursor:pointer;' /><input type="reset" name="reset" value="Reset" style='width:80px; color:#cccccc; background-color:#135cae; cursor:pointer;' /></p>
<p style="text-align:center;"><b>For reset the  search run with empty fields</b></p>
</div>


The solution was the use of sessions Joomla.

An demo of search is here
PicoPaco 18 Jun, 2010
Hi, I use this code to filter my results:
<?php
$search_array = array('leverantor', 'skapadAv'); 
$where = array();
foreach ( $search_array as $search ) {
  $value = JRequest::getVar($search, '' , 'post');
  if ( $value ) {
    $where[] = " $search LIKE '$value%' ";
  }
}
if ( !empty($where) ) {
  echo " WHERE ".implode(' AND ', $where);
}?>


This works great, but I would need to add a few search fields to filter from another table aswell. I need these fields to get data from another table to get data from the first table. An example: The table that I use in my CC display several columns + some columns connected from another table. These are connected by an ID. I want to be able to filter these values aswell. Anyone done this?

Thanks

Markus
PicoPaco 20 Jun, 2010
What I really need is to do a join select in the Where field. Do anyone know how to do this, it wold be very helpful.

Best regards
Markus
vales 21 Jun, 2010
These are the changes to extension of Chronoconnectivity V2 RC3 Chronoengine to enable the management of multi-table query.

Substantial changes were made to the file in its original version is in this position components/com_chronoconnectivity/libraries/connection.php. The changes are as follows.

Line 198 was replaced by the following commentary and where you removed the reference to a single table named in connection configuration

//$query = "SELECT * FROM ".$MyConnection->connectionrow->tablenames;
$query = "SELECT * FROM ";


Line 214 was included in the variable $ total global statement, which represents the number of records found by the query. This will have the variable $ total fields in the connection header, body and footer and avoid entering new code for calculating the record that is already done by the component.

global $mainframe, $total;


Line 229 was replaced by the following commentary and where you removed the reference to a single table named in connection configuration

//$database->setQuery( "SELECT count(*) FROM ".$MyConnection->connectionrow->tablenames." ".trim($WHERE) );
$database->setQuery( "SELECT count(*) FROM "." ".trim($WHERE) );


These changes will now allow you to insert in SQL WHERE conditions not only WHERE but the inclusion of all the tables that we are in the query definition. Virtually everything in the query is normally FROM onwards. This is evident if we look at the rows changed. Basically there will now be included not only WHERE but any control is necessary to define the query. So the field name WHERE SQL connection must be understood in this new meaning.
jjunkie 13 Jul, 2010
Hi everyone, i have used this tutorial to get the search function working as per the first page of this thread, however it only works if i leave the following code out of WHERE SQL:
<?php 
$user =& JFactory::getUser();
?>
WHERE `cf_user_id` = '<?php echo $user->id; ?>'

But i need this code to make sure only records belonging to the logged in user are displayed.

Here is my WHERE SQL code :
<?php 
$user =& JFactory::getUser();
?>
WHERE `cf_user_id` = '<?php echo $user->id; ?>'

<?php
$search_array = array('gname', 'numguests'); 
$where = array();
foreach ( $search_array as $search ) {
  $value = JRequest::getVar($search, '' , 'post');
  if ( $value ) {
    $where[] = " $search LIKE '%$value%' ";
  }
}
if ( !empty($where) ) {
  echo " WHERE ".implode(' AND ', $where);
}?>

It only works if i take the following code out:
<?php 
$user =& JFactory::getUser();
?>
WHERE `cf_user_id` = '<?php echo $user->id; ?>'

But as i mentioned, i need this so only the records belonging to a particular user are displayed, if i leave it out everyones records are displayed and are searchable.

This is the error that comes up (example searching for John Smith):

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE gname LIKE '%John Smith%'' at line 3 SQL=SELECT count(*) FROM jos_chronoforms_RSVPv1 WHERE `vcode` = '69' WHERE gname LIKE '%John Smith%'
Warning: Invalid argument supplied for foreach() in ...htdocs/joomla/components/com_chronoconnectivity/libraries/connection.php on line 300
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE gname LIKE '%John Smith%'' at line 3 SQL=SELECT count(*) FROM jos_chronoforms_RSVPv1 WHERE `vcode` = '69' WHERE gname LIKE '%John Smith%'


Can someone please help me? Do i need to implement some sort of 'AND' in the search query somewhere?

Many thanks

jjunkie
GreyHead 13 Jul, 2010
Hi jjunkie,

Yes, you do need an AND. And the code it there to do it for you if you use it correctly. ChronoConnectivity does require some PHP knowledge - you may need to get someone to work on this with you.

Your code will be outputting something like:

WHERE `cf_user_id` = '999' WHERE `column_a` LIKE '%ABC%' AND `column_b` LIKE '%DEF%'

This will break the MySQL query

<?php
$user =& JFactory::getUser();
$search_array = array('gname', 'numguests');
$where = array();
if ( $user->id ) {
  $where[] = " `cf_user_id` = ". $user->id." ";
}
foreach ( $search_array as $search ) {
  $value = JRequest::getVar($search, '' , 'post');
  if ( $value ) {
    $where[] = " $search LIKE '%$value%' ";
  }
}
if ( !empty($where) ) {
  echo " WHERE ".implode(' AND ', $where);
}?


Bob
jjunkie 14 Jul, 2010
Hi Bob,

Many thanks for this, I'm trying my best to pick up everything and get up to speed, unfortunately the learning curve is pretty steep as this is a new career for me ! The posts on the forum are very helpful as are of course your feedback posts, I was able to implement your code and now the search works !

Initially errors were coming up, but i fixed after i spotted a syntax error

  $where[] = " `cf_user_id` = ". $user->id." ";

should be

  $where[] = " cf_user_id = ". $user->id." ";

So hopefully im getting better at PHP 😀

Thanks again

joomlajunkie
GreyHead 14 Jul, 2010
Hi jjunkie ,

The backticks around the column name are correct - but they are backticks `` not single quotes.

The code will probably work without them but it's better practice to add them or to use ".$db->nameQuote('cf_user_id')."

Bob
jjunkie 14 Jul, 2010
Hi Bob,
Thanks for that, i had single quotes in the code i have reinstated the backticks and its still working!

I have also successfully implemented sortable table names by reading your post multiple times, and with the very generous help of the original poster tamarteleco. The thread is

sorttable table ChronoConnectivity:
http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=12&t=18199

I have implemented the original request, i.e. click to sort table titles, however i have found with the required 'Enable Form tags' set to NO, the search facility does not work.

If i set it to YES, then the sortable names dont work.

Could you please help me here as i need both of these to work, i need the search and the sortable table names.

Many thanks Bob

jjunkie
GreyHead 14 Jul, 2010
Hi jjunkie,

IIRC the sortable columns require a form tag with name='adminForm' (this is the standard for the Joomla backend). If you use 'Enable form tags' it adds form tags with a different name.

The answer is to add form tags by hand with the <form name='adminForm' . . . > tag in the header, before your filter fields and the </form> tag in the footer after any </table> or {pagination} code.

Bob
jjunkie 14 Jul, 2010
Hi Bob,

Thanks for this, looking at the code, i believe i have included the form name=adminForm in the header (i think i reader it is referenced in joomla.javascript.js) and closed with the </form> tag in the footer as you described after the {pagination} code.

I have in the header:
<form name="adminForm" id="adminForm" method="post"
action="index.php?option=com_chronoconnectivity&connectionname=RSVPData">


And in the footer:
</form>


Here is my code:

HEADER:
<div style="float:right">
Search for a <b>Guest name</b>: <input type="text" name="gname">
<b>No. of Guests</b>: <input type="text" name="numguests">
<input type="submit" value="Search" name="undefined" style='width:80px; color:#cccccc; background-color:#222222; cursor:pointer;' /></div> 
{new_record}<br />

<?php
$filter_order =& JRequest::getString('filter_order', '', 'post');
$filter_order_Dir =& JRequest::getString('filter_order_Dir', '', 'post');
?>

<form name="adminForm" id="adminForm" method="post"
action="index.php?option=com_chronoconnectivity&connectionname=RSVPData">
<div style='padding:15px 0; width:100%;'>
<input type='hidden' name='filter_order' id='filter_order' value='<?=$filter_order?>' />
<input type='hidden' name='filter_order_Dir' id='filter_order_Dir' value='<?=$filter_order_Dir?>' />



<table class="table_status_overview"  border="0" cellpadding="2"
cellspacing="0">
<thead>
<tr>
<th style="font-weight: bold;font-size:12px; width:
114px;padding-top:5px;padding-bottom:5px;padding-left:2px;"><?=JHTML::_('grid.sort','Guest Name','gname',@$filter_order_Dir,@$filter_order
)?></th>
<th style="font-weight: bold;font-size:12px; width:
332px;"><?=JHTML::_('grid.sort','Response','radio0',@$filter_order_Dir,@$filter_order
)?></th>
<th style="font-weight: bold;font-size:12px; width:
70px;"><?=JHTML::_('grid.sort','Guests','numguests',@$filter_order_Dir,@$filter_order)?></th>
<th style="font-weight: bold;font-size:12px; width:
126px;"><?=JHTML::_('grid.sort','Date Submitted','recordtime',@$filter_order_Dir,@$filter_order)?></th>
</tr>
</thead>
</table>


BODY:
<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="0">
  <tbody>
    <tr<?php if ($i % 2) echo ' style="background-color: #EBEBEB;"';?>>
      <td style="width: 12%;">{gname}</td>
      <td style="width: 35%;">{radio0}</td>
      <td style="width: 4%;">{numguests}</td>
      <td style="width: 13%;">{recordtime}</td>
      <td style="width: 10%;">{edit_record}</td>
    </tr>
  </tbody>
</table>
<?php $i++ ?>


FOOTER:
<div class="clr" style="border-bottom: 3px solid #6389B4; padding:0px;
margin-bottom: 10px;"></div>
<div align="right">{pagination}</div>
</form>
<br />


Is this correct?

Many thanks

jjunkie
GreyHead 14 Jul, 2010
Hi jjunkie,

That looks good to me though the test is 'Does it work'.

A couple of small comments:

a) I think you will need to add global $i; to the header and the body boxes to get the row marker to carry forward correctly.

b) I would only put a <tr>. . .</tr> in the body section and move the <table>, <tbody> and </table>, </tbody> into the header and footer boxes. This will keep the table cells aligned correctly.

Bob
jjunkie 15 Jul, 2010
Hi Bob,

Thanks for this, however im not sure how to implement these changes as the the two elements of this code i.e the sortable table names, and search functionality DO work, just not at the same time. They work exclusively depending on whether the enable form tags setting is on or off.

The code for each is complete and working, i just need something to enable them to work at the same time.

Im sorry if i didn't understand your post correctly.

jjunkie
GreyHead 15 Jul, 2010
Hi jjunkie,

Ah now I see the problem. Your <form . . .> tag is *after* the filter <input . . .> tag so the filter isn't included in the form. Change the order and all should be OK.

Bob
jjunkie 15 Jul, 2010
Hi Bob 😶

I cant seem to get them to work at the same time, i have rearranged the code as suggested still to no avail.

Search only works with ENABLE FORM TAGS = YES
Sortable table names only works with ENABLE FORM TAGS = NO

Would you be able to check the site for me to see for yourself if i PM the details to you?

Thanks again Bob

jjunkie
GreyHead 15 Jul, 2010
Hi jjunkie,

Have you moved the custom <form. . .> tag ?

By all means email or PM me the site URL and a SuperAdmin login and I'll take a quick look.

Bob
jjunkie 15 Jul, 2010
Hi Bob

I have sent you the details, much appreciated 😀

jjunkie
GreyHead 15 Jul, 2010
Hi jjunkie,

Fixed, I changed the order of the tags.

Bob
jjunkie 15 Jul, 2010
Hi Bob

Your the best! I see you put the form code above the php code right at the start, I was code below this. It works now, perfect.

Thanks again 😀

jjunkie
T34 21 Oct, 2010
I have read all tis topic but don't understand: how to enable the search in "select" fields of Chronoforms?

I have the following code of the dropdown menu in the Chronoform:

...[skiped]...

<div class="cf_item">
  <h3 class="cf_title" style="width: 175px;">You would like to participate as: <span class="red">*</span></h3>
  <div class="cf_fields">
    <select class="cf_select cf_inputbox validate-selection" id="select_6" title="You didn't select value" size="1"  name="select">
      <option value="Client">Client</option>
      <option value="Assistant">Assistant</option>
    </select>
  </div>
</div>

...[skiped]...


I need to search CC form by date + the value of participation for understand how many clients and assistants will arrive to training group.

Please, help me to construct the correct string in Cronoconnectivity searching block for search by other fields (like in the first post) with the searching by "Client" or "Assistant" used dropdown menu as in Chronoform form.
.
GreyHead 21 Oct, 2010
Hi T34,

Have you looked at the Dynamic Filter How-To docs here?

They are much better tutorials than the thread here.

Bob
T34 21 Oct, 2010
Hi Bob!

I have download this article, but at the first example I've see the message "Please select at least 1 table to connect to". There is no name of DB in your first example.

I try to use jos_content DB.

I have the errors viewing CC form:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '" WHERE `title` LIKE '%$title%' "' at line 1 SQL=SELECT count(*) FROM jos_content echo " WHERE `title` LIKE '%$title%' ";

Warning: Invalid argument supplied for foreach() in /volume1/web/joomla/components/com_chronoconnectivity/libraries/connection.php on line 308

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '" WHERE `title` LIKE '%$title%' "' at line 1 SQL=SELECT count(*) FROM jos_content echo " WHERE `title` LIKE '%$title%' ";


What I need to do for solve this problem?
GreyHead 21 Oct, 2010
Hi T34,

I think you'll find that the DB Table setting is covered in the previous tutorial on Static filters.

It looks to me as though You've missed some of the code from the where box - at least the <?php tags and possible more. Please check back with the tutorial again.

Bob
T34 21 Oct, 2010
Thanks, Bob!

I try to make the example from "Static filters for your listing", but when I put the
`title` DESC
in the "Order Field", I see the follow error:
Warning: Invalid argument supplied for foreach() in /volume1/web/joomla/components/com_chronoconnectivity/libraries/connection.php  on line 308


The line 308 is:
		foreach($MyData->getDataRows() as $MyRow){


All steps before the typing `title` DESC is OK.

When I have include the string

{
$mainframe->enqueuemessage('Final query: '.$query);
  return $query;
}


into the connection.php file, I have see the msg:

Final query: SELECT * FROM jos_content ORDER BY `title` DESC ORDER BY `title` DESC ASC

Warning: Invalid argument supplied for foreach() in /volume1/web/joomla/components/com_chronoconnectivity/libraries/connection.php  on line 312


Using the debugger I have the "error 500" with the description (see the attached image).

How can I do to solve?
GreyHead 22 Oct, 2010
Hi T34,

Hmmm just checked on my example and `title` DESC works OK. I get that error if I put ORDER BY `title` DESC in the box :-(

And the query is clearly invalid as the ORDER BY clause is repeated twice - with an extra ASC at the end for good measure :-(
SELECT * FROM jos_content ORDER BY `title` DESC ORDER BY `title` DESC ASC


Have you got the code for Sorting by Column titles on your listing as well? That might cause the problem.

Bob
martinn2009 23 Oct, 2010
Hi,

I already tried to made a sortable table as same as this thread : http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=12&t=18793&hilit=sortable&start=15 and it worked fine when i set "Enable Form tags: No",
but didn't work when I set Enable Form tags: Yes

And I also tried to the drop menu search and it worked fine when i set "Enable Form tags: Yes",
drop down search didn't work when I set Enable Form tags: No

I would like to make those (drop down and sortable) work together.
Any direction ? please help.
GreyHead 24 Oct, 2010
Hi Martin,

For the sortable columns to work you need to add <form> &</form> tags manually to the Header & Footer boxes, the automatic ones will not work. These manual tags should also work OK with a form in the Header box. The only requirement is that the <form> tag comes before any form elements - drop-downs or text boxes.

Bob
T34 25 Oct, 2010
Hi Bob!

Hi T34,

Have you got the code for Sorting by Column titles on your listing as well? That might cause the problem.



This is:

<?php
$style = "";
$style .= " table.cf_listing {
   margin-bottom: 12px;
}
 "; if ( $style) {
   $doc =& JFactory::getDocument();
   $doc->addStyleDeclaration($style);
}
?>
<table class='cf_listing'>
<thead>
  <tr>
     <th>Title</th><th>Hits</th>
  </tr>
</thead>
<tfoot>
  <tr>
    <td colspan='2' style='height:4px; background:silver;'></td>
  </tr>
</tfoot>
<tbody>
GreyHead 26 Oct, 2010
Hi T34,

All looks OK

By all means email or PM me the site URL and a SuperAdmin login and I'll take a quick look.

Bob
GreyHead 27 Oct, 2010
Hi T34,

I took a look and can't see any problem with the Connection code. I'm wondering if there is a problem with the sortable columns hack (see below). Please can you copy & paste here the buildQuery() function from the copy you are using.

Bob

The last change we need to make requires hacking the ChronoConnectivity
code to enable the sort.
Using a suitable editor open the file components/com_chronoconnectivity/
libraries/connection.php and look for the buildQuery() function
around line 190. Add the lines shown here between the // hack and // end
hack comments.

function buildQuery($connectionname)
{
global $mainframe;
$session =& JFactory::getSession();
$MyConnection =& CFChronoConnection::getInstance($connectionname);
$WHERE = $MyConnection->buildWhere($connectionname);
$query = "SELECT * FROM ".$MyConnection->connectionrow->tablenames;
if($MyConnection->connectionrow->SQL){
$query = $query." ".trim($WHERE);
}
// hack
$filter_order = JRequest::getString('filter_order',
$MyConnection->connectionparams('ordersql'), 'post');
$filter_order_Dir = JRequest::getString('filter_order_Dir', 'ASC', 'post');
if ( $filter_order ) {
$query .= " ORDER BY $filter_order $filter_order_Dir ";
}
// end hack
$pageNav = $MyConnection->buildPageNav($MyConnection->connectionrow->name);

T34 27 Oct, 2010

Please can you copy & paste here the buildQuery() function from the copy you are using.


Hi Bob!

Yes, certainly.

This is a function from my connection.php:
function buildQuery($connectionname)
	{
		global $mainframe;
		$session =& JFactory::getSession();
		$MyConnection =& CFChronoConnection::getInstance($connectionname);
		$WHERE = $MyConnection->buildWhere($connectionname);
		
		//todo: get appropriate connection from connections table to get its data!
		$query = "SELECT * FROM ".$MyConnection->connectionrow->tablenames;
		if($MyConnection->connectionrow->SQL){
			$query = $query." ".trim($WHERE);
		}
		//$mainframe->enqueuemessage($query);
		// hack
		if(trim($MyConnection->connectionparams('ordersql'))){
			$query = $query." ORDER BY ".trim($MyConnection->connectionparams('ordersql'));
		}
		$filter_order  = JRequest::getString('filter_order', $MyConnection->connectionparams('ordersql'), 'post');
      $filter_order_Dir  = JRequest::getString('filter_order_Dir', 'ASC', 'post');
      if ( $filter_order ) {
         $query = $query." ORDER BY $filter_order $filter_order_Dir ";
      }
      
      {$mainframe->enqueuemessage('Final query: '.$query);
  return $query;
      }
      	
      	// end hack
		$pageNav = $MyConnection->buildPageNav($MyConnection->connectionrow->name);
		
		$query .= " LIMIT $pageNav->limitstart,$pageNav->limit";	
		return $query;
	}
GreyHead 31 Oct, 2010
Hi T34,

Sorry to have been so long in getting back to this. I think that the problem is that there are few more lines that need to be deleted in your hacked version. These lines are no longer needed and can be commented out or deleted:
      if(trim($MyConnection->connectionparams('ordersql'))){
         $query = $query." ORDER BY ".trim($MyConnection->connectionparams('ordersql'));
      }

Note: These have been replaced by setting a default value in this line:
$filter_order  = JRequest::getString('filter_order', $MyConnection->connectionparams('ordersql'), 'post');

Hopefully this will remove the duplicted ORDER BY clause in the query.

Bob
T34 31 Oct, 2010
Thanks Bob!

I have the follow dwbug string now:

Final query: SELECT * FROM jos_content ORDER BY `title` DESC ASC


but the error too:

Warning: Invalid argument supplied for foreach() in /volume1/web/joomla/components/com_chronoconnectivity/libraries/connection.php  on line 310


and no Titles and Hits are displayed.

The 319 string is:

foreach($MyData->getDataRows() as $MyRow){
GreyHead 31 Oct, 2010
Hi T34,

That was a bit tougher to pin down. I think that replacing 'ASC' with '' in this line should fix it.
$filter_order_Dir  = JRequest::getString('filter_order_Dir', 'ASC', 'post');

Bob
T34 31 Oct, 2010
I have replace to:

$filter_order_Dir  = JRequest::getString('filter_order_Dir', "ASC", 'post');


but have the same problem. 😟
GreyHead 31 Oct, 2010
Hi T34,

Sorry . . . it should be
$filter_order_Dir  = JRequest::getString('filter_order_Dir', '', 'post');
Remove the ASC but leave the quotes.

Bob
T34 31 Oct, 2010
Yyyyyyesssss!!!

It is.

Thanks a lot, Bob!🙂

Studing further...
T34 01 Nov, 2010
Hi Bob!

I can't use the "Clear" button😟

You can see this trouble here.

WHERE SQL:
<?php
$title = JRequest::getString('title', '', 'post');
if ( $title ) {
    echo " WHERE `title` LIKE '%$title%' ";
}
?>


HEADER:
<?php
$doc =& JFactory::getDocument(); $doc->addScript('includes/js/joomla.javascript.js');
?>

<?php
$script = "";
$script .= "
$('clear').addEvent('click', function() {
   $('title').value = '';
});
";
if ( $script ) {
   $doc =& JFactory::getDocument();
   $script = "window.addEvent('domReady', function() { $script });"; $doc->addScriptDeclaration($script);
}
?>

<?php
$style = "";
$style .= " table.cf_listing {
   margin-bottom: 12px;
}
 "; if ( $style) {
   $doc =& JFactory::getDocument();
   $doc->addStyleDeclaration($style);
}
?>

<?php
$title = JRequest::getString('title', '', 'post');
?>

<input type='text' name='title' id='title' value='<?php echo $title; ?>' /> <input type='submit' name='filter' id='filter' value='Найти' /> <input type='button' name='clear' id='clear' value='Clear' />

<table class='cf_listing'>
<thead>
  <tr>
     <th>Title</th><th>Hits</th>
  </tr>
</thead>
<tfoot>
  <tr>
    <td colspan='2' style='height:4px; background:silver;'></td>
  </tr>
</tfoot>
<tbody>


FOOTER:
  </tbody>
</table>
{pagination}


And when I enable Form tags at the other form, column sorting doesn't work in it. 😲

Where I can find the solutions?
GreyHead 05 Nov, 2010
Hi T34,

There's no listing found at that URL but I can see that you have the MooTools Upgrade Plug-in enabled. This is an optional plug-in that enables the MooTools 1.2 library on your site.

ChronoForms (and many other Joomla! extensions) use the MooTools 1.1.2 library that is installed by default. The ChronoForms Wizard, and other back-end code will not run with the plugin enabled.

If you disable the plug-in then ChronoForms should run correctly.

If you need MooTools 1.2 in the front-end of your site then there is a hack for the plug-in posted in the forums here that will enable the 1.2 library in the front-end only. However the ChronoForms validation code and some other features will not work with this version.

There's a fuller "How-to Document" here that includes fixed files that will let the front-end of ChronoForms work with MooTools 1.2.

Bob
Chris Blair 07 Nov, 2010
Hi,
I have successfully incorporated the SQL search code

<?php
$search_array = array('firstname', 'lastname', 'scrnum');
$where = array();
foreach ( $search_array as $search ) {
  $value = JRequest::getVar($search, '' , 'post');
  if ( $value ) {
    $where[] = " $search LIKE '$value%' ";
  }
}
if ( !empty($where) ) {
  echo " WHERE ".implode(' AND ', $where);
}?>

into my connectivity form but I need it to do more. I have tried various ways of doing this but my efforts either produced a totally blank screen or some SQL error. Unfortunately my knowledge is lacking in this area and I simply cannot get my head around it, hence my request for help.

I am running a search based on values of two input fields (name, date1). What I am looking to achieve is to have the search return records form the db that match the name AND the previous 7 days of date1. For instance, if I input Chris Blair and 07/11/2010 it will return all the records for Chris Blair from 01/11/2010 to 07/11/2010.

Regards & huge appreciation

Chris
GreyHead 07 Nov, 2010
Hi Chris,

It's going to be something like this - but you may need to tune the date code to match the way you are storing dates in the database (this version will work if they are in DATE or DATETIME columns).
<?php
$search_array = array('firstname', 'lastname', 'scrnum');
$where = array();
$name = JRequest::getString($name, '' , 'post');
if ( $name ) {
  $where[] = " `name` LIKE '$name' ";
}
$date = JRequest::getString($date1, '' , 'post');
if ( $date ) {
  $where[] = " (`date` <= '$date' AND `date` > DATE_SUB($date, INTERVAL 1 WEEK) )";
}
if ( !empty($where) ) {
  echo " WHERE ".implode(' AND ', $where);
}?>

Bob
Chris Blair 07 Nov, 2010
Bob,
Thank you yet again for the response. Unfortunately I could not get the code to work at all this time. I have the following in the SQL area:

<?php
$search_array = array('name', 'date1');
$where = array();
$name = JRequest::getString($name, '' , 'post');
if ( $name ) {
  $where[] = " `name` LIKE '$name' ";
}
$date = JRequest::getString($date1, '' , 'post');
if ( $date ) {
  $where[] = " (`date1` <= '$date' AND `date1` > DATE_SUB($date, INTERVAL 1 WEEK) )";
}
if ( !empty($where) ) {
  echo " WHERE ".implode(' AND ', $where);
}?>


I altered your original where it said `date` to `date1` and was unsure if $date1 in the second JRequest was a typo so I tried that with $date and $date1 - noe of this had any positive effect.

Originally I was storing the date as a varchar but following your post I changed it to type Date, and manually inserted some dates into this column as the date field on the CF gets entered as 0000-00-00 (something else I need to get my head round). When I search now for a name and a date nothing happens - no error message, just All records displayed (unfiltered). I think I can just about get my head around what your code is doing - now that I have gotten over the migraine :-) The reality is that I do not have a clue as to where I begin picking this apart.

Just to check my understanding...

what your code is doing is setting up an array to take 2 values which are read in from my input boxes. It then goes through the table for looking for records that are similar to the name entered in the input box and isolates these. On these isolated records it then performs the second part of the request,this time looking for records within that isolated set that are similar to the date entered into the input box. Specifically, dates that are less than or equal to the value entered input box but greater than dates that are a week prior?????

Sorry about all of this - I am an out of work truck driver trying to add strings to my bow - I should have chosen a smaller mountain to climb :-)

Hopefully!

Chris
GreyHead 07 Nov, 2010
Hi Chris,

Apologies, there's a typo in this line
$date = JRequest::getString($date1, '' , 'post');
it should be
$date = JRequest::getString('date1', '' , 'post');


This code is just setting up the WHERE clause part of a MySQL query.

It creates sub-clauses for sub-selections and then strings them all together with AND to get something like
WHERE `a` = 'b' AND `x` > 'y' AND . . .


In this case the first sub-selection is to match the name value; then we use a bit of MySQL syntax to select a date in the one-week range you wanted.

To get the dates to save from your form in MySQL date format you need to set the format string on the form General tab to 'Y-m-d' assuming that you are using a datepicker.

Good luck with the learning

Bob
Chris Blair 07 Nov, 2010
Hi Bob,
Still no luck! I made the change (addressing the typo in the code) and the effect that had was to display every record in the table if the search input only contained a name, and to display no records at all if both a name and date were used as the search criteria. I also made an assumption that if

$date = JRequest::getString('date1', '' , 'post');

was the correct synax it should follow that

$name = JRequest::getString('name', '' , 'post');

should also be the case? As to why it's not working is still beyond me. Note to self: Learn to walk before running :-)

One thing is for sure, if I was confused before I am even more so now. These little beauties ` " ' are going to be the death of me. I think I understand " and ' but a search for ` gave me nothing - is that one particular to CF/CC?

I have I think, after all my time on this mortal coil finally learned patience.

TIA and Regards

Chris
GreyHead 08 Nov, 2010
Hi Chris,

The pesky backticks first `` they are used by MySQL to mark table and column names (as opposed to plain text strings). Most of the time you don't need them but I tend to put them in anyhow to avoid the 1 time in 20 when they break the code.

To debug the MySQL query you need to get access to the database tables. You can do this with PHPMyAdmin (probably available through your ISP's CPanel) or the Joomla! EasySQL extension which is not so powerful but runs through the Site Admin.

Then add some code to let you see the out put you are getting
if ( !empty($where) ) {
  echo " WHERE ".implode(' AND ', $where);
  $where = " WHERE ".implode(' AND ', $where);
  $mainframe->enqueuemessage('$where: '.print_r($where, true));
}?>
Thus should out put the WHERE part of the MySQL query to the screen. If you copy this and put SELECT * FROM `#__some_tablename` in front of the WHERE part and test it in PHPMyAdmin to see what errors you get.

Bob
Chris Blair 08 Nov, 2010
Hi Bob,
Tried hard to get something out of your last post but given my lack of experience/knowledge I am not sure whether my actions and therefore my results were correct and accurate.

I opened PHPMyAdmin and navigated to the table in question - jos_chronoforms_timesheet - then opened the SQL tab for that table. In the SQL area I placed the following code.

SELECT * FROM `jos_chronoforms_timesheet` WHERE SELECT * FROM `jos_chronoforms_timesheet` WHERE <?php
$search_array = array('name', 'date1');
$where = array();
$name = JRequest::getString('name', '' , 'post');
if ( $name ) {
  $where[] = " `name` LIKE '$name' ";
}
$date = JRequest::getString('date1', '' , 'post');
if ( $date ) {
  $where[] = " (`date1` <= '$date' AND `date1` > DATE_SUB($date, INTERVAL 1 WEEK) )";
}
if ( !empty($where) ) {
  echo " WHERE ".implode(' AND ', $where);
  $where = " WHERE ".implode(' AND ', $where);
  $mainframe->enqueuemessage('$where: '.print_r($where, true));
}?>

The output from running that query on the table was
[attachment=0]Screen shot 2010-11-08 at 18.13.23.png[/attachment]

Thank you for your patience in helping me through this.

Regards

Chris
GreyHead 08 Nov, 2010
Hi Chris,

Definitely not the right code to post.

Now you've added the $mainframe->enqueuemessage code you should see an 'info' message at the top of the ChronoConnectivity listing page that starts $where:

What does that message say?

Bob
Chris Blair 08 Nov, 2010
Sorry Bob!!!!
I don't get any info message. When I run a search on the CC listing it still behaves as previously mentioned i.e. either all records or no records are displayed. There is no other info displayed on that page at all???

Regards

Chris
GreyHead 08 Nov, 2010
Hi Chris.

Please post a link to the listing so we can take a quick look.

Bob
Chris Blair 08 Nov, 2010
Hi Bob,
I sent you a PM with url and login details to get to the cc form.

I have been tinkering with PHPMyAdmin and God knows how but I managed to construct the following query

SELECT * FROM `jos_chronoforms_timesheet` WHERE (`name` = 'Eddie Walsh') AND (`date1` <= '2010-11-08') AND (`date1` >= DATE_SUB('2010-11-08', INTERVAL 1 WEEK) )


Which produced the result I am looking for. You will notice a couple of minor changes to the query you sent earlier. I reproduced this in the CC form WHERE box, substituting the literal dates for variable names andgot exactly the same result as before i.e. ALL records or NONE at all.

Regards

Chris
T34 09 Nov, 2010
Hi Bob!

There's not listing found at that URL but I can see that you have the MooTools Upgrade Plug-in enabled. This is an optional plug-in that enables the MooTools 1.2 library on your site.
ChronoForms (and many other Joomla! extensions) use the MooTools 1.1.2 library that is installed by default. The ChronoForms Wizard, and other back-end code will not run with the plugin enabled.

If you disable the plug-in then ChronoForms should run correctly.



I have kill my old test site and have start to build it again, you know. Mootools Upgrade is swithed off from the beginning, I use the standard template rhuk_milkyway and there are only 3 additional components in my Joomla! now:
[list]Kunena forum
CF
CC[/list]
But I have the same problem. I do all steps according your fine How-To, and all functions work before the step "Adding a ‘Clear filter’ button" of "Dynamic filters for your listing 1" How-To. Clear button doesn't work. I have try to use it on 2 web servers, but I haven't effect.

Nothing happens using Opera, Firefox and Safary browsers (I didn't try to use the other, because I have Macbook Pro). The page dosn't reloads after I click 'Clear' button. At all. I mean javascript dosn't work ONLY with code of 'Clear'. But why?😲

Please, if you'll have the time a little, look at the site (the address and login is the same) for help me to resolve this strange problem.

There's a fuller "How-to Document" here that includes fixed files that will let the front-end of ChronoForms work with MooTools 1.2.


Thanks, Bob! I really need to "marriage" CC, CF and the new mootools, but I can't do that before I resolve the previous problems of CC dynamic filtering on my site.
GreyHead 09 Nov, 2010
Hi T34,

It's working now.

There were two problems:

(a) the MooTools library wasn't being loaded at all. I'm not sure why but I added this line to the Header box to force it.
JHTML::_('behavior.mootools');


(b) there was a typo in the JavaScript that may well be mine. This line
$script = "window.addEvent('domready', function() { $script });";
had domReady with an upper-case R which is incorrect.

Bob
GreyHead 09 Nov, 2010
Hi Chris,

The only problem was a stray ) at the end of the SELECT statement. I took that off and it seemed to work fine.

I've also added the names as a drop-down built from the timesheet table that you can use as an example.

And I installed EasySQL so that I could check the database tables.

Bob
Chris Blair 09 Nov, 2010
Hi Bob,
I am at a complete loss with regards to thanking you for your patience and help in resolving this issue. The quality of support I have received has been quite exceptional. I am indebted to you sir.

Many, many thanks and huge regard to you.

Chris
T34 10 Nov, 2010
[quote="GreyHead"]There were two problems:

(a) the MooTools library wasn't being loaded at all. I'm not sure why but I added this line to the Header box to force it.
JHTML::_('behavior.mootools');
[/quote]

Thanks a lot, Bob!

It really works. But I can't understand why mootools dosn't loads without this string. I have install Joomla! 1.5.21 again at the other directory on my local server, without any additions, only for testing. And I have install ONLY CC. But when I try to use "Clear" option, it doesn't works without the string [code]JHTML::_('behavior.mootools');[/code]again. I mean there is serious problem of common working of CC with Joomla! 1.5.21, because I see this at two virtual hosts and at my local server. Always the same problem is.

(b) there was a typo in the JavaScript that may well be mine. This line

$script = "window.addEvent('domready', function() { $script });";
had domReady with an upper-case R which is incorrect.


Yes, the upper-case R is in How-To.
T34 13 Nov, 2010
Hi Bob!

I have a problem that jjunkie had: Sorting tables doesn't work with "Enable Form tags" switched to "Yes". But it this case the tag <form...> is in the code.

This test site is absolutely clear. Only CF and CC (with modules and plugins) are installed. There are no additions more. Mootools Upgrade plugin is OFF. However javascript doesn't loads in CC form for sorting columns works. So I need to include the code:
<?php
$doc =& JFactory::getDocument();
$doc->addScript('includes/js/joomla.javascript.js');
?>
to the Header.

But when I switch "Enable Form tags" to "Yes" javascript stops to work again, and there isn't sorting of columns.

The full code of my CC form is:

HEADER:
<div align="center">{pagination}</div>

<form name='adminForm' method='post' action='index.php?option=com_chronoconnectivity&connectionname=zayavki_constel'>

<?php
$doc =& JFactory::getDocument();
$doc->addScript('includes/js/joomla.javascript.js');
?>

<?php
$filter_order =& JRequest::getString('filter_order', '', 'post');
$filter_order_Dir =& JRequest::getString('filter_order_Dir', '', ‘post’);
?>

<input type='hidden' name='filter_order' id='filter_order' value='<?php echo $filter_order; ?>' />

<input type='hidden' name='filter_order_Dir' id='filter_order_Dir' value='<?php echo $filter_order_Dir; ?>' />

<table style="text-align: left; width: 100%; border-top: 1px dotted black; border-bottom: 1px dotted black;" cellpadding="2" cellspacing="0"> 
  <thead>
    <tr>
      <th style="font-weight: bold; width: 5%;"><?php echo JHTML::_('grid.sort', '№ ', 'cf_id', @$filter_order_Dir, @$filter_order ); ?></th>
      <th style="font-weight: bold; width: 15%;"><?php echo JHTML::_('grid.sort', 'Имя ', 'name_01', @$filter_order_Dir, @$filter_order ); ?></th>
      <th style="font-weight: bold; width: 15%;";><?php echo JHTML::_('grid.sort', 'E-mail ', 'email_01', @$filter_order_Dir, @$filter_order ); ?></th>
      <th style="font-weight: bold; width: 10%;"><?php echo JHTML::_('grid.sort', '№ телефона ', 'phone_01', @$filter_order_Dir, @$filter_order ); ?></th>
      <th style="font-weight: bold; width: 8%;"><?php echo JHTML::_('grid.sort', 'Дата ', 'date_01', @$filter_order_Dir, @$filter_order ); ?></th>
      <th style="font-weight: bold; width: 7%;"><?php echo JHTML::_('grid.sort', 'Клиент ', 'radio0', @$filter_order_Dir, @$filter_order ); ?></th>
      <th style="font-weight: bold; width: 10%;"><?php echo JHTML::_('grid.sort', 'Ассистент ', 'radio1', @$filter_order_Dir, @$filter_order ); ?></th>
      <th style="font-weight: bold; width: 15%;"><?php echo JHTML::_('grid.sort', 'Время заявки ', 'recordtime', @$filter_order_Dir, @$filter_order ); ?></th>
      <th style="font-weight: bold; width: 8%;">Изменить</th>
      <th style="font-weight: bold; width: 7%;">Удалить</th> 
    </tr>
  </thead>
<tbody>


BODY:
    <tr<?php if ($i % 2) echo ' style="background-color: #F4F4F4;"';?>>
      <td style="width: 5%;">{cf_id}</td>
      <td style="width: 15%;">{name_01}</td>
      <td style="width: 15%;">{email_01}</td>
      <td style="width: 10%;">{phone_01}</td>
      <td style="width: 8%;">{date_01}</td>
      <td style="width: 7%;">{radio0}</td>
      <td style="width: 10%;">{radio1}</td>
      <td style="width: 15%;">{recordtime}</td>
      <td style="width: 8%;">{edit_record}</td>
      <td style="width: 7%;">{delete_record}</td>
      <?php $i++ ?>
    </tr>


FOOTER:
    <tr><td style="align: left;">{new_record}</td></tr>
  </tbody>
</table>
</form>
<div align="center">{pagination}</div>


Please, look at code and help me to find a solution. URL of the connection output is here, the login is the same (see PM before), if it's needed.
Immovable 14 Nov, 2010
Is it possible for you to list a couple of sites that use search this way? I would be interested in testing the functionality because I am thinking of changing my site.

http://www.immovableproperty.co.za
South Africa.
GreyHead 18 Nov, 2010
Hi Immovable,

There are some specialist property extensions for Joomla that might be much better suited to your needs.

Bob
T34 18 Nov, 2010
Hi Bob!

I'm glad to see you in this topic again!🙂

Are there any news about the common work "Enable Form tags" and "Sorting Columns"?
GreyHead 18 Nov, 2010
Hi T34,

Sorry, mised that.

Sorting columns requires that the form name is 'adminForm'. If you enable form tags ChronoConnectivity gives the form a different name.

So if you use sorting columns you must leave 'Enable Form Tags' as 'No' and add the tags by hand in the Header and Footer boxes.

Bob
T34 19 Nov, 2010
Hi Bob!

Thanks for reply! 🙂

It's not a good news, but the solution is to use 2 CC forms for 1 CF (may be on 1 page, using plugin), I think: the first CC form for Searching and the second one for Sorting of the Columns. I'll try to build that.
GreyHead 19 Nov, 2010
Hi T34,

There should be no need for that. You can have search and sortable columns in the same listing. That works perfectly well.

But you must use hand-coded form tags instead of the ChronoConnectivity generated tags.

Bob
T34 19 Nov, 2010

But you must use hand-coded form tags instead of the ChronoConnectivity generated tags.


🙄 Hmm... I don't understand what you mean.
GreyHead 19 Nov, 2010
Hi T34,

So if you use sorting columns you must leave 'Enable Form Tags' as 'No' and add the tags by hand in the Header and Footer boxes.

I think that the code for the Form tags is in the Sorting Columns document.

Bob
T34 19 Nov, 2010
Hi Bob!

Sorry, I'm really stupid. 😟 What kind of tag do you mean? Please, post the name of tag or any little example with the tags included manually, if it's possible.
GreyHead 19 Nov, 2010
Hi T34,

3. There’s one more change before we are done with the Header box. We need
to add our own <form> tag as the Joomla code requires that the form name
is ‘adminForm’ and the ChronoConnectivity tags use another name. Insert the
tag before any other form HTML is output:

<form name='adminForm' method='post'
action='index.php?option=com_chronoconnectivity&connectionname=connection_name'>

Replace ‘connection_name’ with the name of your Connection listing.

That's it for the Header box.

4. In the Footer box add the </form> tag to close the form. Make sure that it
comes after the {pagination} tag if you have used it there.


Bob
T34 13 Dec, 2010
Hi All!

I need to make searching using dropdown menu with the strings created by the SQL query:
    SELECT DISTINCT `select_1` AS `select_2`, `time`
    FROM `jos_chronoforms_zayavka_reg`
    ORDER BY time ASC;


The user needs to select one option from dropdown menu, then press "Submit" button and see the result of searching with all the strings of DB table where the selected option is.

How can I do that in CC form? What kind of code I need to insert to the WHERE SQL and HEADER fields?
GreyHead 14 Dec, 2010
Hi T34,

I think that this is in the Dynamic Filters 2 tutorial here.

Bob
T34 14 Dec, 2010
Hi Bob!

I have this tutorial, but there are examples for searching something IN categories displayed in dropdown menu. I need the other solution. I need to use the string of dropdown menu as a value in "search" field. So I SELECT all existed values in the some column of DB using SQL query for build the dropdown menu. For example if the menu string is "Bob" I need to find all rows where "Bob" is in the column "name". 🙂
adricist 14 Dec, 2010
Hi Bob,

Can you please help me with a simple introductory query I would like to have on a specific Chronoconnectivity Form. I currently have a table that stores registrations for multiple events. I have also been able successfully to add queries in the Header that allow to filter by event. What I am now trying to achieve is to have a new form that only displays records from one specific event. I am guessing it is going to be a simple matter to place a 1 line query in the WHERE SQL or Header tag but I am unsure of what the code should be.

So if we assume that I have the following parameters

Table name = jos_cp_registrations
Field to query by = {event}
Field content I am after = "XMas Lunch"

Can you please help me structring this query?

Thanks,
Adri
adricist 15 Dec, 2010
Don't worry Bob,

I found my answer in your "ChronoConnectivity static filters.pdf" Tutorial!

Here is the answer for me

WHERE `event` LIKE '%XMas%'

It works perfectly

Thanks,
Adri
GreyHead 15 Dec, 2010
Hi Adri,

Yes, that's good. If you know the exact value then you could also use WHERE `event` = 'XMas_Lunch'

Bob
T34 15 Dec, 2010
Hi Bob!

Please, give me any example for solve the problem that is described in my previous post here!
GreyHead 15 Dec, 2010
Hi T34,

I'm not sure how this is very different from the examples in the tutorials?

For example if the menu string is "Bob" I need to find all rows where "Bob" is in the column "name".


<?php
$where = array();
. . .
$name = JRequest::getVar('name', array(), 'post', 'array');
$temp = array();
if ( count($name) ) { 
  foreach ( $name as $v ) {
    $temp[] = " `body` = '$v' ";
  }
  $where[] = " ( ".implode(' OR ', $temp)." ) ";
}
. . .
echo "WHERE ".implode(' AND ', $where);
?>

Bob
T34 18 Dec, 2010
Hi Bob!

Thanks for reply!

It should be better to post a code here, I think.🙂

There are:

WHERE SQL:
<?php
$select_1 = JRequest::getString('select_1', '', 'post');
if ( $select_1 ) {
  echo " WHERE `select_1` LIKE '%$select_1%' ";
}
?>


HEADER:
<div align="center">{pagination}</div>

<?php
//JHTML::_('behavior.mootools');

$db =& JFactory::getDBO();
$count = $db->loadResult();
?>

<?php
$filter_order =& JRequest::getString('filter_order', '', 'post');
$filter_order_Dir =& JRequest::getString('filter_order_Dir', '', ‘post’);
?>

<form name='adminForm' method='post' action='index.php?option=com_chronoconnectivity&connectionname=trythree'>

<?php
$select_1 = JRequest::getString('select_1', '', 'post');
?>

<?php
$select_3 = JRequest::getString('select_3', '', 'post');
?>

<?php
$script = "";
$script .= "
$('clear').addEvent('click', function() {
$('select_1').value = '';
});
";
if ( $script ) {
$doc =& JFactory::getDocument();
$script = "window.addEvent('domready', function() { $script });";
$doc->addScriptDeclaration($script);
}
?>

<div>
<select class="cf_inputbox"
        id="select_3" size="1" name="select_3" title="">
      <option value=''>Выберите, кликнув здесь</option>
<?php
if (!$mainframe->isSite() ) {return;}
$db =& JFactory::getDBO();
$query = "
  SELECT DISTINCT `select_1` AS `select_2`
    FROM `#__chronoforms_zayavka_reg`
    ORDER BY time ASC;
";
$db->setQuery($query);
$options = $db->loadAssocList();
foreach ( $options as $o ) {
  echo "<option value='".$o[select_2]."'>".$o[select_2]."</option>";
}
?>
     </select> <input type='submit' name='select_3' id='select_3' value='Найти' />
</div>

<input type='hidden' name='filter_order' id='filter_order' value='<?php echo $filter_order; ?>' />

<input type='hidden' name='filter_order_Dir' id='filter_order_Dir' value='<?php echo $filter_order_Dir; ?>' />

<input type='text' name='select_1' id='select_1' value='<?php echo $select_1; ?>' /> <input type='submit' name='filter' id='filter' value='Найти' /> <input type='button' name='clear' id='clear' value='Очистить' />

<?php
if ( !$count ) {
  echo "<div>Ничего не найдено</div>";
}
?>

<table style="text-align: left; width: 100%; border-top: 1px dotted black; border-bottom: 1px dotted black;" cellpadding="2" cellspacing="0">


<thead>

<tr>

<th style="font-weight: bold; width: 15%;"><?php echo JHTML::_('grid.sort', 'Имя ', 'name', @$filter_order_Dir, @$filter_order ); ?></th>

<th style="font-weight: bold; width: 15%;";><?php echo JHTML::_('grid.sort', 'E-mail ', 'email', @$filter_order_Dir, @$filter_order ); ?></th>

<th style="font-weight: bold; width: 15%;"><?php echo JHTML::_('grid.sort', '№ телефона ', 'phone', @$filter_order_Dir, @$filter_order ); ?></th>

<th style="font-weight: bold; width: 25%;"><?php echo JHTML::_('grid.sort', 'Дата ', 'select_1', @$filter_order_Dir, @$filter_order ); ?></th>

<th style="font-weight: bold; width: 10%;"><?php echo JHTML::_('grid.sort', 'Клиент ', 'radio0', @$filter_order_Dir, @$filter_order ); ?></th>

<th style="font-weight: bold; width: 10%;"><?php echo JHTML::_('grid.sort', 'Ассистент ', 'radio1', @$filter_order_Dir, @$filter_order ); ?></th>

<th style="font-weight: bold; width: 5%;">Изменить</th>

<th style="font-weight: bold; width: 5%;">Удалить</th> 

</tr>


</thead>

</table>


BODY:
<table style="text-align: left; width: 100%;" cellpadding="2" cellspacing="0" border="0">
    <tr<?php if ($i % 2) echo ' style="background-color: #F4F4F4;"';?>>
      <td style="width: 15%;">{name}</td>
      <td style="width: 15%;">{email}</td>
      <td style="width: 15%;">{phone}</td>
      <td style="width: 25%;">{select_1}</td>
      <td style="width: 10%;">{radio0}</td>
      <td style="width: 10%;">{radio1}</td>
      <td style="width: 5%;">{edit_record}</td>
      <td style="width: 5%;">{delete_record}</td>
     <?php $i++ ?>
   </tr>
</table>


FOOTER:
<table style="text-align: left; width: 100%; border-top: 1px dotted black;" cellpadding="2" cellspacing="0">
<thead>
<tr><th>{new_record}</th></tr>
</thead>
</table>
<script type="text/javascript"> 
window.addEvent('domready', function() { 
var limit_select = $('limit').options; 
if ( !limit_select ) return; 
for ( var i = 0; i < limit_select.length; i++ ) { 
if ( limit_select[i].value == 0 ) { 
limit_select[i].value = 250; 
limit_select[i].innerHTML = '250'; 
} 
} 
}); 
</script>
</form>
<div align="center">{pagination}</div>


I see the dropdown menu but when I select one option and press the filter button of this menu:
<input type='submit' name='select_3' id='select_3' value='Найти' />
("Найти"), the page is reloaded but filter doesn't work.

I have think that I need to modify the query in WHERE SQL field. But I don't sure. How I need to modify it (ore other fields) for the dropdown filter will work?
betsy042 19 Dec, 2010
Very informative site and helpful...and its great to be here 🙂
T34 02 Jan, 2011
Hi Bob!

I have rewrite my code, but it dosn't work

There is a message
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 SQL=SELECT count(*) FROM jos_chronoforms_zayavka_reg WHERE `select_1` IN ()
Warning: Invalid argument supplied for foreach() in /home/rasstan9/public_html/components/com_chronoconnectivity/libraries/connection.php on line 309
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 SQL=SELECT count(*) FROM jos_chronoforms_zayavka_reg WHERE `select_1` IN ()
after I press "Filter" ("Найти") button.

My form includes:

WHERE SQL:
<?php
// create the empty array
$where = array();
// check the text filter
$filter_text = JRequest::getString('filter_text', '', 'post');
if ( $filter_text ) {
   $where[] = "( `name` LIKE '%$filter_text%'
      OR `select_1` LIKE '%$filter_text%'
      OR `secname` LIKE '%$filter_text%'
      OR `email` LIKE '%$filter_text%'
      OR `phone` LIKE '%$filter_text%'
      OR `submit_time` LIKE '%$filter_text%' )";
}
// check the event filter
$filter_event =& JRequest::getVar('filter_event', array(), 'post', 'array');
if ( count($filter_event) ) {
   $filter = implode(', ', $filter_event);
   $where[] = " `select_1` IN ($filter) ";
}
if ( count($where) ) {
   $where = implode(' AND ', $where);
   echo " WHERE $where ";
}
?>


HEADER:
<?php
// JHTML::_('behavior.mootools');

// get the number of records returned

$db =& JFactory::getDBO();
global $count;
$count = $db->loadResult();

// add style & script snippets
$style = "";
$style .= "
table.cf_listing {
   margin-bottom: 12px;
}
";

if ( $style) {
   $doc =& JFactory::getDocument();
   $doc->addStyleDeclaration($style);
}

$script = "";
$script .= "
$('clear').addEvent('click', function() {
   $('filter_text').value = '';
   $('filter_event').selectedIndex = -1;
});
";

if ( $script ) {
   $doc =& JFactory::getDocument();
   $script = "window.addEvent('domready', function() { $script });";
   $doc->addScriptDeclaration($script);
}

// get the previous filter string
$filter_text = JRequest::getString('filter_text', '', 'post');

$query =
   " SELECT `select_1`, `name`, `secname`, `email`, `phone`, `submit_time`, `radio0`, `radio1`
      FROM `#__chronoforms_zayavka_reg`
      GROUP BY `select_1`
      ORDER BY `select_1`;
";
$db->setQuery($query);
$data = $db->loadObjectList();

//$('filter_text').value = '';

?>

<select name='filter_event[]' id='filter_event' multiple='multiple' size='5' >
<?php
$filter_event =& JRequest::getVar('filter_event', array(), 'post', 'array'); foreach ( $data as $d ) {
   $selected = '';
   if ( in_array($d->id, $filter_event) ) {
      $selected = "selected='selected'";
   }
      echo "<option value='".$d->id."' $selected >".$d->select_1."</option>";
}
?> 
</select>
<br />
<!-- display the filter box and buttons -->
<input type='text' name='filter_text' id='filter_text' value='<?php echo $filter_text; ?>' /> <input type='submit' name='filter' id='filter' value='Найти' /> <input type='submit' name='clear' id='clear' value='Очистить' />

<!-- start the listing table -->

<div align="center">{pagination}</div>

<table class='cf_listing' style="text-align: left; width: 100%; border-top: 1px dotted black; border-bottom: 1px dotted black;" cellpadding="2" cellspacing="0">

<thead>

<tr>

<th style="font-weight: bold; width: 25%;">Событие</th>

<th style="font-weight: bold; width: 15%;">Имя</th>

<th style="font-weight: bold; width: 15%;";>E-mail</th>

<th style="font-weight: bold; width: 15%;">№ телефона</th>

<th style="font-weight: bold; width: 10%;">Клиент</th>

<th style="font-weight: bold; width: 10%;">Ассистент</th>

<th style="font-weight: bold; width: 5%;">Изменить</th>

<th style="font-weight: bold; width: 5%;">Удалить</th> 

</tr>

</thead>

<tbody style="text-align: left; width: 100%;" cellpadding="2" cellspacing="0" border="0">


BODY:
    <tr>
      <td style="width: 25%;">{select_1}</td>
      <td style="width: 15%;">{name}</td>
      <td style="width: 15%;">{email}</td>
      <td style="width: 15%;">{phone}</td>
      <td style="width: 10%;">{radio0}</td>
      <td style="width: 10%;">{radio1}</td>
      <td style="width: 5%;">{edit_record}</td>
      <td style="width: 5%;">{delete_record}</td>
   </tr>


FOOTER:
<tr><td>{new_record}</td></tr>
</tbody>
</table>
<?php
// get the row count and show the pagination if needed
global $count;
if ( $count ) {
?>
{pagination}
<?php
}
?>


Please, help me to find my mistakes and to force this form to work properly!
GreyHead 02 Jan, 2011
Hi T34,

I think that the problem is with this piece of code in the Header box

$query =
   " SELECT `select_1`, `name`, `secname`, `email`, `phone`, `submit_time`, `radio0`, `radio1`
      FROM `#__chronoforms_zayavka_reg`
      GROUP BY `select_1`
      ORDER BY `select_1`;
";
$db->setQuery($query);
$data = $db->loadObjectList();

//$('filter_text').value = '';

?>

<select name='filter_event[]' id='filter_event' multiple='multiple' size='5' >
<?php
$filter_event =& JRequest::getVar('filter_event', array(), 'post', 'array'); 
foreach ( $data as $d ) {
   $selected = '';
   if ( in_array($d->id, $filter_event) ) {
      $selected = "selected='selected'";
   }
      echo "<option value='".$d->id."' $selected >".$d->select_1."</option>";
}
?>
</select>
The option value you are setting is $d->id but the query doesn't include an `id` column.

Looking at the code in the WHERE box I think that should be $d->select_1 but I can't be certain.

Bob
T34 02 Jan, 2011
Thanks, Bob!

I have modify the Header section using "$d->select_1", and now it is:
<?php
// JHTML::_('behavior.mootools');

// get the number of records returned

$db =& JFactory::getDBO();
global $count;
$count = $db->loadResult();

// add style & script snippets
$style = "";
$style .= "
table.cf_listing {
   margin-bottom: 12px;
}
";

if ( $style) {
   $doc =& JFactory::getDocument();
   $doc->addStyleDeclaration($style);
}

$script = "";
$script .= "
$('clear').addEvent('click', function() {
   $('filter_text').value = '';
   $('filter_event').selectedIndex = -1;
});
";

if ( $script ) {
   $doc =& JFactory::getDocument();
   $script = "window.addEvent('domready', function() { $script });";
   $doc->addScriptDeclaration($script);
}

// get the previous filter string
$filter_text = JRequest::getString('filter_text', '', 'post');

$query =
   " SELECT `select_1`, `name`, `secname`, `email`, `phone`, `submit_time`, `radio0`, `radio1`
      FROM `#__chronoforms_zayavka_reg`
      GROUP BY `select_1`
      ORDER BY `select_1`;
";
$db->setQuery($query);
$data = $db->loadObjectList();

//$('filter_text').value = '';

?>

<select name='filter_event[]' id='filter_event' multiple='multiple' size='5' >
<?php
$filter_event =& JRequest::getVar('filter_event', array(), 'post', 'array'); foreach ( $data as $d ) {
   $selected = '';
   if ( in_array($d->id, $filter_event) ) {
      $selected = "selected='selected'";
   }
      echo "<option value='".$d->select_1."' $selected >".$d->select_1."</option>";
}
?> 
</select>
<br />
<!-- display the filter box and buttons -->
<input type='text' name='filter_text' id='filter_text' value='<?php echo $filter_text; ?>' /> <input type='submit' name='filter' id='filter' value='Найти' /> <input type='submit' name='clear' id='clear' value='Очистить' />

<!-- start the listing table -->

<div align="center">{pagination}</div>

<table class='cf_listing' style="text-align: left; width: 100%; border-top: 1px dotted black; border-bottom: 1px dotted black;" cellpadding="2" cellspacing="0">

<thead>

<tr>

<th style="font-weight: bold; width: 25%;">Событие</th>

<th style="font-weight: bold; width: 15%;">Имя</th>

<th style="font-weight: bold; width: 15%;";>E-mail</th>

<th style="font-weight: bold; width: 15%;">№ телефона</th>

<th style="font-weight: bold; width: 10%;">Клиент</th>

<th style="font-weight: bold; width: 10%;">Ассистент</th>

<th style="font-weight: bold; width: 5%;">Изменить</th>

<th style="font-weight: bold; width: 5%;">Удалить</th> 

</tr>

</thead>

<tbody style="text-align: left; width: 100%;" cellpadding="2" cellspacing="0" border="0">


But after I select the value in dropdown menu and press "Filter" button, I see the other error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.11/11:00-19:00/"По-Другому")' at line 1 SQL=SELECT count(*) FROM jos_chronoforms_zayavka_reg WHERE `select_1` IN (09.01.11/11:00-19:00/"По-Другому")

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.11/11:00-19:00/"По-Другому")' at line 1 SQL=SELECT count(*) FROM jos_chronoforms_zayavka_reg WHERE `select_1` IN (09.01.11/11:00-19:00/"По-Другому")
Warning: Invalid argument supplied for foreach() in /home/rasstan9/public_html/components/com_chronoconnectivity/libraries/connection.php on line 309

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.11/11:00-19:00/"По-Другому")' at line 1 SQL=SELECT count(*) FROM jos_chronoforms_zayavka_reg WHERE `select_1` IN (09.01.11/11:00-19:00/"По-Другому")
GreyHead 02 Jan, 2011
Hi T34,

There's a general problem with the labels here that I've answered in the "Insert the SELECTION value from DB to the other field" thread.

There's also a specific problem of some missing quotes that give rise - in part at least - to this error. This code
// check the event filter
$filter_event =& JRequest::getVar('filter_event', array(), 'post', 'array');
if ( count($filter_event) ) {
   $filter = implode(', ', $filter_event);
   $where[] = " `select_1` IN ($filter) ";
}
will work OK if the result array is a series of integers. Here though they are strings and it will not work unless the strings are quoted.
// check the event filter
$filter_event =& JRequest::getVar('filter_event', array(), 'post', 'array');
if ( count($filter_event) ) {
  $db =& JFactory::getDBO();
  foreach ( $filter_event as $k =>$v ) {
    $filter_event[$k] = $db->quote($v);
  }
  $filter = implode(', ', $filter_event);
  $where[] = " `select_1` IN ($filter) ";
}
The foreach loop will add the necessary quotes to the results.

BUT This will probably give you another problem because your result strings contain quotes either the escaping will stop the matches working in the database or they will break the query :-(

My reply to that problem is over in the other thread.

Bob
T34 02 Jan, 2011
WOW! Thanks a lot, Bob! Now it works properly! 😀

But I don't understand how can I use this example for solve my problem about I write in the "Insert the SELECTION value from DB to the other field" thread?

In CF form I have only one field (instead WHERE SQL and HEADER fields in CC form). How to use "$k => $v" there? Can you give the whole code of this <select>, if I don't need the some fields for each part of my events?
iluca 23 Jan, 2011
Thank you so very much Benblee.

These two tutes (this one and the original CC one) have made my life a lot easier.

Love your work 😀

Cheers
~iluca (lowliest of n00bs)
GreyHead 05 Apr, 2011
Hi jdsilva,

Please see this tutorial plus the more detailed ones here especially the two Dynamic Filter tutorials.

Bob
jllav03 02 Dec, 2011
I'm using Joomla! 1.5.23 Stable. Does that version allow me to use ChronoConnectivity? I don't see that option under the Components tab. Thanks
GreyHead 02 Dec, 2011
Hi jllav03,

Have you downloaded and installed it?

Bob
spectsteve7 06 Dec, 2011
Hi All,

I've followed this post and did the set up as noted. On submit of my search button nothing happens on my side. Have I missed a step?

Thanks in advanced.
GreyHead 06 Dec, 2011
Hi spectsteve7,

Probably you have missed something - but it's impossible to say what without at least a small hint about what you have done :-(

Bob
jllav03 06 Dec, 2011
Hi spectsteve7, I think I had the same problem.

Under the General tab of your ChronoConnectivity form go to the Connection View Settings and change the 'Enable Form tags' from No to Yes. That should allow you to submit your form.

P.S. Thanks GreyHead, I installed ChronoConnectivity and it works great!
crea2k 11 Dec, 2011
Is there a tutorial for this for joomla 1.6 /1.7 and v4 of chronoforms ?
GreyHead 13 Dec, 2011
Hi crea2k,

Not as far as I know. There is a tutorial on using the DB Multi-Record Loader and a couple of threads like this about setting up searches and filters though.

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