Copyright © 2005-2008 Andrea Tincani

AndreaPHP | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Welcome to my new Site)Next Topic (Geo target function) New Topic New Poll Post Reply
AndreaPHP Forum : PHP General : SQL
Poster Message
usdrunk
Level: Protégé

Registered: 20-03-2006
Posts: 6

icon SQL

Hi buddy,
I am using tForum, I want to print out 2 list of the most viewed of 2 board in the same page.

Here is my code

<?php
@require('./includes/grab_globals.php');
$GLOBALS['query_count'] = 0;
@require('./language/text.php');
@require('./templates/buttons.php');
@require('./includes/template_parser.php');
@require('./db.php');
@require('./includes/functions.php');
$GLOBALS['start_time'] = Getmicrotime();
$fSettings = GetSettings();
@require('./includes/gzip_begin.php');
$ent['TopDownBoardID'] = (isset($_GET['TopDownBoardID'])) ? intval($_GET['TopDownBoardID']) : 0;
$ent['LastBoardID'] = (isset($_GET['LastBoardID'])) ? intval($_GET['LastBoardID']) : 0;
$TopicID = (isset($_GET['TopicID'])) ? intval($_GET['TopicID']) : 0;
$MsgID = (isset($_GET['MsgID'])) ? intval($_GET['MsgID']) : 0;
$page = (isset($_GET['page'])) ? intval($_GET['page']) : 0;
$sql = new DB_SQL;
$sql1 = new DB_SQL;
$sql2 = new DB_SQL;

$templates = SplitTemplate(ReadTemplate('topview'));
$ent['ScriptURL'] = $fSettings['ScriptURL'];
$ent['SiteURL'] = $fSettings['SiteURL'];
$ent['ForumName'] = $fSettings['ForumName'];
@require(SCRIPT_ABS_PATH.'/includes/boardpermdefs.php');
@require(SCRIPT_ABS_PATH.'/includes/topictypes.php');


$query = "SELECT M.* FROM " . PREFIX . "messages M, " . PREFIX . "topics T WHERE M.TopicID = T.TopicID AND T.BoardID = " . $TopDownBoardID . " ORDER BY T.numViews DESC LIMIT 3";
$sql->query($query);
if ($sql->num_rows()>0)
{ $total_top++;
while ($row = $sql->get_assoc())
{ $ent['TopDownSubjectURL'] = 'viewtopic.php?TopicID='.$row['TopicID'];
$ent['TopDownSubject'] = $row['Subject'];
echo ParseTemp($templates['loop'],$ent);
}
}

$query = "SELECT M.* FROM " . PREFIX . "messages M, " . PREFIX . "topics T WHERE M.TopicID = T.TopicID AND T.BoardID = " . $LastBoardID . " ORDER BY T.numViews DESC LIMIT 3";
$sql->query($query);
if ($sql->num_rows()>0)
{ $total_top++;
while ($row = $sql->get_assoc())
{ $ent['LastSubjectURL'] = 'viewtopic.php?TopicID='.$row['TopicID'];
$ent['LastSubject'] = $row['Subject'];
echo ParseTemp($templates['loop'],$ent);
}
}
?>


and my template

<!part_loop>
<a href="<!TopDownSubjectURL>"><!TopDownSubject></a>
<a href="<!LastSubjectURL>"><!LastSubject></a><br>
<!part_last>


The result is something like

1st topic of board 1
2nd topic of board 1
3rd topic of board 1      1st topic of borad 2
3rd topic of board 1      2nd topic of borad 2
3rd topic of board 1      3rd topic of borad 2



what I want is


1st topic of board 1      1st topic of borad 2
2nd topic of board 1      2nd topic of borad 2
3rd topic of board 1      3rd topic of borad 2


Could any one give help. Thank you very much!

[Edited by usdrunk on 20-03-2006 at 10:16 PM GMT]

21-03-2006 at 04:15 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 35

icon Re: SQL

try this

<? php

for ($i=0;$i<3;$i++) {
$query "SELECT M.* FROM " PREFIX "messages M, " PREFIX "topics T WHERE M.TopicID = T.TopicID AND T.BoardID = " $TopDownBoardID " ORDER BY T.numViews DESC LIMIT ".$i.",1";
$sql->query($query);
if (
$sql->num_rows()>0)
$total_top++;
while (
$row $sql->get_assoc())
$ent['TopDownSubjectURL'] = 'viewtopic.php?TopicID='.$row['TopicID'];
$ent['TopDownSubject'] = $row['Subject'];
}
}

$query "SELECT M.* FROM " PREFIX "messages M, " PREFIX "topics T WHERE M.TopicID = T.TopicID AND T.BoardID = " $LastBoardID " ORDER BY T.numViews DESC LIMIT ".$i.",1";
$sql->query($query);
if (
$sql->num_rows()>0)
$total_top++;
while (
$row $sql->get_assoc())
$ent['LastSubjectURL'] = 'viewtopic.php?TopicID='.$row['TopicID'];
$ent['LastSubject'] = $row['Subject'];
}
}
echo 
ParseTemp($templates['loop'],$ent);

//end for

?>




[Edited by admin on 21-03-2006 at 08:11 AM GMT]

____________________________
AndreaVB

21-03-2006 at 07:11 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
usdrunk
Level: Protégé

Registered: 20-03-2006
Posts: 6

icon Re: SQL

Thank you! You're pro, man. But I don't know why nobody visit this forum?

21-03-2006 at 05:35 PM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 35

icon Re: SQL

thanks for your appreciations,

we have not a lot of visitors maybe just because the site is quite young, I opened it just one year ago... I've tried to spread the word around, getting some link back but with no luck at this time.
there are also not many posts in the forum so people take a look and then move away...I guess...

I hope we'll have more visitors to come in the next months

    

____________________________
AndreaVB

22-03-2006 at 08:18 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaPHP Forum : PHP General : SQL
Previous Topic (Welcome to my new Site)Next Topic (Geo target function) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: AndreaVB

Copyright © 2005-2008 Andrea Tincani

Powered by: tForum tForum Edition b0.92p1
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team.