function buildquery($q) { $query = ''; foreach ( $q as $qe ) { if ( $qe['operator'] == 'string' ) { $query.= 'strpos($row[\''.$qe['variable'].'\'],"'.$qe['value'].'") !== false'; } else { $query.= '$row[\''.$qe['variable'].'\']'.$qe['operator'].$qe['value']; //$query.= '$row[\''.$qe['variable'].'\']'.$qe['operator'].$qe['value']; } $query.= " and "; } $query = substr($query, 0, -5); // remove last " and " return $query; } #Table 'mytable' fields are name, email, and site (table created in example1.php) include "csvdb.swishdb.com.php"; $db = new LiteDB(); $db->open("table") or die("cannot open table 'table'"); #variable 'total' of object $db tells number of rows in table $q[1] = array('variable'=>'R1', 'operator'=>'>=', 'value'=>'0.01'); $q[0] = array('variable'=>'R2', 'operator'=>'>=', 'value'=>'0.02'); #$q[2] = array('variable'=>'Date', 'operator'=>'string', 'value'=>"2009-10"); print_r($q); print_r(buildquery($q)); echo "\n"; $query = buildquery($q); //die(); if($db->total >0) { for($i=1; $i<=$db->total; $i++) { $row = $db->get_row($i); echo $query."\n"; #if ( $row['R1'] > 0.02 and $row['R2'] < 0.03 ) { if ( 0 ) { #echo "ROW.No.$i - Name : $row[name], Email : $row[email], Site : $row[site]
"; echo "ROW.No.$i - Date: $row[Date], R1 : $row[R1], R2 : $row[R2]"; echo "\n"; } } }