1

Topic: SQL in Userstats mod

Hi!

I haven't enough php or sql experience to solve this problem just by googling php docs, so I'm asking you for help

You see, userstats mod allows admin to see most read (popular) topics, it shows a table like this

Topic                               Number of Views
        Topic Name                             10

All I want is to convert a string Topic Name to a link pointing to appropriate topic. If this script already can get topic subject (by somehow correlateing topic_id from statviews_all table with subject from topics table) then it should be easy to get topic id too.

This lines print topic subject and Number of Views

while($stat_topics = $db->fetch_assoc($result))  {
     echo '<tr>
     <td class="tc2" style="width:70%">'.$stat_topics['subject'] . '</td>
     <td class="tcr" style="width:30%;text-align:left">'.$stat_topics['topicct'] . '</td>
     </tr>';

$stat_topics['subject'] should be replaced by link like <a href='viewtopic.php?id=$stat_topics[topic_id]'>
$stat_topics['subject']  </a>

But I don't know how to trace associative array to see if it contains keys with topics id. How can I get something like exception when trying to get inexistent key? Instead of empty values.

And, after all, I doubt that $stat_topics array contains keys with ids.

Here is the $result query

$query = 'SELECT count(s.topic_id) as topicct, t.subject FROM '.$db->prefix.'statviews_all s INNER JOIN '.$db->prefix.'topics t ON s.topic_id=t.id WHERE logind >= \''.$start.'\' and logind <= \''.$end . '\' group by topic_id order by topicct DESC';
      $result = $db->query($query) or error('unable to fetch topic information', __FILE__, __LINE__, $db->error());

Please, help me to modify code, so it'll be able to produce links to topics.

Re: SQL in Userstats mod

The query:

$query = 'SELECT count(s.topic_id) as topicct, t.subject, t.id AS topic_id FROM '.$db->prefix.'statviews_all s INNER JOIN '.$db->prefix.'topics t ON s.topic_id=t.id WHERE logind >= \''.$start.'\' and logind <= \''.$end . '\' group by topic_id order by topicct DESC';
      $result = $db->query($query) or error('unable to fetch topic information', __FILE__, __LINE__, $db->error());

That should fix it

3

Re: SQL in Userstats mod

Thank you Smartys, one hundred times Thank You! smile

I wonder how you can so easily understand such a complex (at least for me) sql queries. I wish I have as much experience as you do.

4

Re: SQL in Userstats mod

Enemy wrote:

I wonder how you can so easily understand such a complex (at least for me) sql queries.

That's why he's called Smartys wink

5

Re: SQL in Userstats mod

indeed tongue we all love him