PDA

View Full Version : What is missing here?


dontpanic
01-24-2004, 03:21 AM
I made the query, template and page code using existing, working elements in use elsewhere. My questions are these:

1. Why does this return only one result, when it should obviously return 10?

2. Why does it not return the correct results...the top article has over 6000 views.

The page in question (and there are two sets of this problem on it) is: http://www.mcseworld.com/forums/library.php

The query, template and page code were revised from that which drives this page: http://www.mcseworld.com/forums/lastthreads.php where they work quite nicely.

The SQL query:// Get Popular Articles

$populararticle = $DB_site->query("SELECT * FROM thread WHERE forumid IN (252,253,254,255,256,257,258,259,260,261,262,263,2 64) ORDER BY views DESC LIMIT 10");

while ($populararticles = $DB_site->fetch_array($populararticle))
{

eval('$library_populararticles = "' . fetch_template('library_populararticles') . '";');
}

// Get Popular ArticlesThe forumid numbers listed are the forums that house my Library articles...and of course, I would like 10 rows returned by the query from most popular (most view) down.

The template:<table border="0" cellpadding="2" width="100%" style="border-collapse: collapse" bordercolor="#111111">


<tr><span class="smallfont">
<td class="alt1Active" width="60%" align="left" valign="top"><span class="smallfont"><a href="showthread.php?$session[sessionurl]goto=lastpost&t=$populararticles[threadid]">$populararticles[title]</td>
<td class="alt1Active" width="20%" align="left" valign="top"><span class="smallfont"><a href="member.php?$session[sessionurl]find=lastposter&t=$populararticles[threadid]">$populararticles[lastposter]</a></b></td>
<td class="alt1Active" width="20%" align="left" valign="top"><span class="smallfont">$populararticles[views]</b></td>
</span>
</tr>


</table>The actual code on the page:<!-- popular articles -->
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">

<tbody>
<tr>
<td class="thead" colspan="3">
<a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('forumhome_articles)"><img id="collapseimg_forumhome_articles" src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_forumhome_articles].gif" alt="" border="0" /></a>
Most Popular Articles Posted in the Library
</td>
</tr>
</tbody>
<tbody id="collapseobj_forumhome_articles" style="$vbcollapse[collapseobj_forumhome_articles]">
<tr><span class="smallfont">
<td class="alt1Active" width="60%" align="left" valign="top"><span class="smallfont"><b>Article</b></td>
<td class="alt1Active" width="20%" align="left" valign="top"><b>Author</b></td>
<td class="alt1Active" width="20%" align="left" valign="top"><b>Views</b></td>
</span>
</tr>
<tr>
<td class="alt1Active" colspan="3">$library_populararticles</td>
</tr>
</tbody>
</table>
<!-- popular articles -->Thanks in advance to anyone who can help me figure this one out.

assassingod
01-24-2004, 07:55 AM
Try:

// Get Popular Articles
$populararticle = $DB_site->query("
SELECT *
FROM thread
WHERE forumid IN (252,253,254,255,256,257,258,259,260,261,262,263,2 64)
ORDER BY views DESC
LIMIT 10
");
while ($populararticles = $DB_site->fetch_array($populararticle))
{
eval('$library_populararticles .= "' . fetch_template('library_populararticles') . '";');
}
// Get Popular Articles


If the views still aren't right, try changing ORDER BY views DESC to ORDER BY views ASC

dontpanic
01-24-2004, 11:04 AM
Great, that was it...I guess it was just too sloppy for its own good. :)

Now, I have another question...I cannot seem to extract the date/time properly.

Here is my query:// Get Recent Articles
$lastarticle = $DB_site->query("
SELECT *
FROM thread
WHERE forumid IN (252,253,254,255,256,257,258,259,260,261,262,263,2 64)
ORDER BY dateline DESC
LIMIT 10
");
while ($lastarticles = $DB_site->fetch_array($lastarticle))
{
eval('$library_lastarticle .= "' . fetch_template('library_lastarticle') . '";');
}
$lastarticlesdate = vbdate($vboptions['dateformat'], $lastarticles['dateline']);
$lastarticlestime = vbdate($vboptions['timeformat'], $lastarticles['dateline']);
// Get Recent Articles And here is the template it feeds into:<table border="0" width="100%" bordercolor="#111111">
<tr>
<td class="alt1Active" width="70%" align="left"><span class="smallfont"><a href="showthread.php?$session[sessionurl]goto=lastpost&t=$lastarticles[threadid]">$lastarticles[title]</a></span></td>
<td class="alt1Active" width="20%" align="left"><span class="smallfont"><a href="member.php?$session[sessionurl]find=lastposter&t=$lastarticles[threadid]">$lastarticles[lastposter]</a></span></td>
<td class="alt1Active" width="10%" align="left"><span class="smallfont">$lastarticlesdate</span></td>
</tr>
</table>Any ideas on where I screwed up extracting the date information? I'm not using the time information yet, but may want to soon.

Thanks again for your help!

g-force2k2
01-24-2004, 04:46 PM
dontpanic,

Instead of:

while ($lastarticles = $DB_site->fetch_array($lastarticle))
{
eval('$library_lastarticle .= "' . fetch_template('library_lastarticle') . '";');
}
$lastarticlesdate = vbdate($vboptions['dateformat'], $lastarticles['dateline']);
$lastarticlestime = vbdate($vboptions['timeformat'], $lastarticles['dateline']);

It should be:

while ($lastarticles = $DB_site->fetch_array($lastarticle))
{
$lastarticlesdate = vbdate($vboptions['dateformat'], $lastarticles['dateline']);
$lastarticlestime = vbdate($vboptions['timeformat'], $lastarticles['dateline']);
eval('$library_lastarticle .= "' . fetch_template('library_lastarticle') . '";');
}

Because you want the extract the date and time of each article so you must perform it during the while loop and also you have to place the code before the eval so that the lastarticlsesdate and time variables are included in the template.

Cheers,
g-force2k2

dontpanic
01-24-2004, 11:44 PM
Oh duh, thanks! Working perfectly now. :)