Skip to content

Instantly share code, notes, and snippets.

@therealchiko
Last active September 21, 2016 11:23
Show Gist options
  • Save therealchiko/994f4c1632e6a2ad1141 to your computer and use it in GitHub Desktop.
Save therealchiko/994f4c1632e6a2ad1141 to your computer and use it in GitHub Desktop.
<?php
//all the info for this business is available inside $_SESSION['businessinfo']
//let's rearrange it.
$f3->set('bid', $f3->get('SESSION.businessinfo')->bid);
$businessinfo =new DB\SQL\Mapper($db, 'business_info');
//this sets the keywords array with all the words we are looking for.
$f3->set('keywords', explode(',',$businessinfo->load(array('bid=?', $f3->get('bid')))['keywords']));
//let's clean up the array and remove empty elements, then attach keywords in a way regexp understands for 'like'
$keys = implode('|', array_filter($f3->get('keywords')));
//query the database, looking for matches in the ads table.
$q = $db->prepare("SELECT * FROM ads WHERE adtitle REGEXP :keywords");
$q->execute(array(':keywords' => $keys));
$q->setFetchMode(PDO::FETCH_ASSOC);
$q->fetchAll();
$f3->set('resultrow', $q);
print_r($f3->get('resultrow'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment