forum topicposts
robmoorman - 02/03/2006 16:50 (laatste wijziging 02/03/2006 16:50)
PHP interesse
ok ik heb dus een scriptje wat de laatste posts laat zien...
maar hoe maak ik juist dat ik alleen maar 1 topic zien en dus niet als er 3x achter elkaar word geposts 3x het topic erin staat. Een topictitel mag dus maar 1x voorkomen in "de output"...
http://www.energy-gaming.org/site.php
mijn code:
<?php
global $db;
global $do;
$tpl = new TemplatePower("blocks/forum/forum.tpl");
$tpl->prepare();
$query = $db->query("SELECT timestamp, topicid FROM forum_posts ORDER BY id DESC LIMIT 0,10");
$topics = array();
while ($sql = $db->dump($query))
{
$tpl->newBlock("topics");
$bg = ($i++ % 2) ? "bg2" : "bg1";
$topicid = $sql["topicid"];
$title = $do->setLenght(htmlentities($db->getContent("title", "forum_topics", "id", $topicid)), 16);
$date = $do->parseDate($sql["timestamp"], "time");
$comments = $db->numRows($db->query("SELECT * FROM forum_posts WHERE topicid='".$topicid."'"));
$topics[] = $topicid;
$tpl->assign(array(
"bg" => $bg,
"topicid" => $topicid,
"title" => $title,
"date" => $date,
"comments" => $comments
));
}
$tpl->printToScreen();
?>
<?php
$tpl = new TemplatePower( "blocks/forum/forum.tpl" ) ;
$tpl -> prepare ( ) ;
$query = $db -> query ( "SELECT timestamp, topicid FROM forum_posts ORDER BY id DESC LIMIT 0,10" ) ;
while ( $sql = $db -> dump ( $query ) )
{
$tpl -> newBlock ( "topics" ) ;
$bg = ( $i ++ % 2 ) ? "bg2" : "bg1" ;
$topicid = $sql [ "topicid" ] ;
$title = $do -> setLenght ( htmlentities ( $db -> getContent ( "title" , "forum_topics" , "id" , $topicid ) ) , 16 ) ; $date = $do -> parseDate ( $sql [ "timestamp" ] , "time" ) ;
$comments = $db -> numRows ( $db -> query ( "SELECT * FROM forum_posts WHERE topicid='" . $topicid . "'" ) ) ;
$topics [ ] = $topicid ;
"bg" => $bg ,
"topicid" => $topicid ,
"title" => $title ,
"date" => $date ,
"comments" => $comments
) ) ;
}
$tpl -> printToScreen ( ) ;
?>
ieamdn een idee, dank u
4 antwoorden
Gesponsorde links
nathanael - 02/03/2006 16:54 (laatste wijziging 02/03/2006 17:23)
HTML gevorderde
ik zou de tijden en de waarden controlen.
dus als er binnen 3 seconden de zelfde waarden wordt gepost, dan zeggen dat het verzoek al is verzonden oid...
edit:
Citaat:
Gebruikersnaam: g0dlike ( online )
Status: PHP interesse
robmoorman - 02/03/2006 17:17
PHP interesse
en hpe verwerk ik dat in php ???
Maarten - 02/03/2006 17:36
Erelid
Je maakt een array $topics.
Dan ga je je mysql-output met laatste topics af, en alvorens deze weer te geven controleer je of het ID van het topic nog niet voorkomt in je array topics.
Zoja -> niks weergeven
Zonee -> weergeven en het ID opslaan in de array $topics
robmoorman - 02/03/2006 17:50
PHP interesse
ke thxn het werkt
<?php
//*************************************
//* *
//* Copyright: Rob Moorman *
//* *
//*************************************
global $db;
global $do;
$tpl = new TemplatePower("blocks/forum/forum.tpl");
$tpl->prepare();
$query = $db->query("SELECT timestamp, topicid FROM forum_posts ORDER BY id DESC LIMIT 0,10");
$topics = array();
while ($sql = $db->dump($query))
{
$topicid = $sql["topicid"];
if (!in_array($topicid, $topics))
{
$tpl->newBlock("topics");
$bg = ($i++ % 2) ? "bg2" : "bg1";
$topicid = $sql["topicid"];
$title = $do->setLenght(htmlentities($db->getContent("title", "forum_topics", "id", $topicid)), 16);
$date = $do->parseDate($sql["timestamp"], "time");
$comments = $db->numRows($db->query("SELECT * FROM forum_posts WHERE topicid='".$topicid."'"));
$topics[] = $topicid;
$tpl->assign(array(
"bg" => $bg,
"topicid" => $topicid,
"title" => $title,
"date" => $date,
"comments" => $comments
));
}
}
$tpl->printToScreen();
<?php
//*************************************
//* *
//* Copyright: Rob Moorman *
//* *
//*************************************
$tpl = new TemplatePower( "blocks/forum/forum.tpl" ) ;
$tpl -> prepare ( ) ;
$query = $db -> query ( "SELECT timestamp, topicid FROM forum_posts ORDER BY id DESC LIMIT 0,10" ) ;
while ( $sql = $db -> dump ( $query ) )
{
$topicid = $sql [ "topicid" ] ;
{
$tpl -> newBlock ( "topics" ) ;
$bg = ( $i ++ % 2 ) ? "bg2" : "bg1" ;
$topicid = $sql [ "topicid" ] ;
$title = $do -> setLenght ( htmlentities ( $db -> getContent ( "title" , "forum_topics" , "id" , $topicid ) ) , 16 ) ; $date = $do -> parseDate ( $sql [ "timestamp" ] , "time" ) ;
$comments = $db -> numRows ( $db -> query ( "SELECT * FROM forum_posts WHERE topicid='" . $topicid . "'" ) ) ;
$topics [ ] = $topicid ;
"bg" => $bg ,
"topicid" => $topicid ,
"title" => $title ,
"date" => $date ,
"comments" => $comments
) ) ;
}
}
$tpl -> printToScreen ( ) ;
Gesponsorde links
Dit onderwerp is gesloten .