SELECT books.id, books.title, books.year, COUNT(articles.book)
FROM books, articles
WHERE articles.book = books.id
GROUP BY books.id, books.title, books.year
SELECT books.id, books.title, books.year, COUNT(articles.book)
FROM books LEFT JOIN articles ON books.id=articles.book
GROUP BY books.id, books.title, books.year
$arr = array('word1', 'word2', 'word3');
$n = count($arr);
for ($i = 1; $i <= $n; $i++) {
$pos[$i] = $i-1;
$c[$i] = 1;
$pr[$i] = 1;
}
$c[$n] = 0;
foreach($pos as $p)
echo $arr[$p],' ';
echo "<br>";
$i = 1;
while ($i < $n) {
$i = 1;
$x = 0;
while ($c[$i] == $n-$i+1) {
$pr[$i] = 1-$pr[$i];
$c[$i] = 1;
$x += $pr[$i];
$i++;
}
if ($i < $n) {
$k = $pr[$i] ? $c[$i]+$x : $n-$i+1-$c[$i]+$x;
$t = $pos[$k];
$pos[$k] = $pos[$k+1];
$pos[$k+1] = $t;
foreach($pos as $p)
echo $arr[$p],' ';
echo "<br>";
$c[$i]++;
}
}
word1 word2 word3
word2 word1 word3
word2 word3 word1
word3 word2 word1
word3 word1 word2
word1 word3 word2
function combinations($words)
{
if (count($words) == 1) {
return [$words];
};
$combinations = [];
$i = 0;
do {
$first_word = array_shift($words);
foreach (combinations($words) as $cmb) {
$combinations[] = array_merge([$first_word], $cmb);
};
array_push($words, $first_word);
} while (++$i < count($words));
return $combinations;
};
$combinations = combinations(explode(' ', 'word1 word2 word3 word4'));
print_r($combinations);