Skip to content

Instantly share code, notes, and snippets.

<?php
$s = new SphinxClient;
$s->setServer("localhost", 9312);
$s->setMatchMode(SPH_MATCH_ANY);
$s->setSortMode(SPH_SORT_RELEVANCE);
$s->setMaxQueryTime(3);
$s->setLimits(0,10);
$s->addQuery('test', 'test1');
CREATE TABLE search_table (
id INT(10) UNSIGNED NOT NULL,
weight INTEGER NOT NULL,
query VARCHAR(3072) NOT NULL,
group_id INTEGER, INDEX(query)
) ENGINE=SPHINX CONNECTION="sphinx://localhost:9312/test1";
mysql> SELECT * FROM interests JOIN search_table ON (interests.iid = search_table.id) WHERE query='philosophy of science;mode=any';
+-----+-----------------------+------+---------------------+----+--------+--------------------------------+----------+
| iid | title | body | modified | id | weight | query | group_id |
+-----+-----------------------+------+---------------------+----+--------+--------------------------------+----------+
| 31 | Philosophy of Science | NULL | 2010-08-01 01:36:26 | 31 | 6 | philosophy of science;mode=any | 0 |
| 30 | Philosophy | NULL | 2010-08-01 01:36:22 | 30 | 1 | philosophy of science;mode=any | 0 |
| 32 | Philosophy of Math | NULL | 2010-08-01 01:36:30 | 32 | 1 | philosophy of science;mode=any | 0 |
+-----+-----------------------+------+---------------------+----+--------+--------------------------------+----------+
<?php
foreach($tzlist as $items) {
foreach($items as $item) {
echo "INSERT INTO timezones (timezone) VALUES ('" . $item . "');";
}
}
<?php
foreach($tzlist as $items) {
foreach($items as $item) {
echo "INSERT INTO timezones (timezone) VALUES ('" . $item . "');";
}
}
<?php
static $regions = array(
'Africa' => DateTimeZone::AFRICA,
'America' => DateTimeZone::AMERICA,
'Antarctica' => DateTimeZone::ANTARCTICA,
'Aisa' => DateTimeZone::ASIA,
'Atlantic' => DateTimeZone::ATLANTIC,
'Europe' => DateTimeZone::EUROPE,
'Indian' => DateTimeZone::INDIAN,
CREATE TABLE timezones (
tid INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
timezone VARCHAR(30) NOT NULL
) ENGINE=InnoDB;
CREATE TABLE users_timezones (
uid INT(11) NOT NULL,
tid INT(11) NOT NULL,
FOREIGN KEY (uid) REFERENCES users(uid),
FOREIGN KEY (tid) REFERENCES timezones(tid)
) ENGINE=InnoDB;
<?php
$len = strlen('America/Argentina/Rio_Gallegos');
echo $len;
SELECT interests.iid, interests.title, COUNT(*)
FROM users_interests
JOIN interests ON interests.iid = users_interests.iid
WHERE users_interests.preference = 'dislike'
GROUP BY interests.iid
ORDER BY COUNT(*) DESC
LIMIT 10;