Forum Moderators: open
$asql = mysql_query("SELECT
novice.id, COUNT(novicaID) FROM novice,novice_komentarji WHERE novice_komentarji.novicaID = novice.id
GROUP BY novice.id ORDER BY novice.id = novice_komentarji.novicaID") or die (mysql_error());
$id = $_GET['id'];
$sql = mysql_query("SELECT * FROM novice
LEFT JOIN (SELECT MAX(id) MAXid FROM novice) M ON id = M.MAXid
WHERE M.MAXid IS NULL ORDER BY id DESC LIMIT 5") or die (mysql_error());
while($urejanje = mysql_fetch_object($sql))
{
$text = $urejanje->novica;
$newtext = substr($text, 0,76);
echo "<span class=povezave>
<p>$urejanje->naslov<br />
<span class=poddatum>$urejanje->datum</span></p>
<span class=imgnovice><img src='images/$izpis->foto'></span>
$newtext... <a href=index.php?pg=novica&id=$urejanje->id>več<br /></a>";
$abc = mysql_fetch_array($asql);
if($abc['COUNT(novicaID)'] >0) {
echo "Komentarji:"; echo $abc['COUNT(novicaID)'];}
else {
echo "Komentarji: 0";
}
echo "</span><br>";
}
| postcount | id | naslov |
+-----------+----+---------------------+
| 5 | 1 | This is title one |
| 2 | 2 | This is title two |
| 0 | 3 | This is title three |
| 5 | 4 | This is title four |
+-----------+----+---------------------+
4 rows in set (0.01 sec)
$sql = mysql_query("SELECT * FROM novice
LEFT JOIN (SELECT MAX(id) MAXid FROM novice) M ON id = M.MAXid
WHERE M.MAXid IS NULL ORDER BY id DESC LIMIT 5" $asql = mysql_query("select (select count(*) from novice_komentarji where novice_komentarji.novicaID=novice.id) as postcount, novice.id, novice.naslov from novice") or die (mysql_error());
$abc = mysql_fetch_array($asql);
if($abc['COUNT(novicaID)'] >0) {
echo "Komentarji:"; echo $abc['COUNT(novicaID)'];}
else {
echo "Komentarji: 0";
}
$asql = mysql_query($query) or die (mysql_error());
while ($abc = mysql_fetch_array($asql)) {
if($abc['postcount'] > 0) {
echo $abc['postcount'] . " comments";
}
else {
echo "No new comments";
}
}
The result I get is 5520 and not 5205.
$asql = mysql_query($query) or die (mysql_error());
while ($abc = mysql_fetch_array($asql)) {
if($abc['postcount'] > 0) {
echo "id: " . $abc['id'] . " title: " . $abc['naslov'] . " " . $abc['postcount'] . " comments<br>";
}
else {
echo "No new comments<br>";
}
}