Google

NukeCoder


View next topic
View previous topic
Post new topic   Reply to topic
Author Message
MASsIVE




Joined: Mar 25, 2007
Posts: 27

PostPosted: Fri May 11, 2007 10:51 am
Reply with quote

Hi All

Just working on some code which requires me to retrieve the last ten news entries with the matching topicimages for each.

What I go so far, very raw any help to get these topic images to appear wuld be greatly appreciated.

Code:
$result = $db->sql_query("SELECT t.topicname, t.topicimage, t.topictext FROM ".$prefix."_stories s LEFT JOIN ".$prefix."_topics t ON t.topicid = s.topic WHERE t.topicid = s.topic");
   $row = $db->sql_fetchrow($result);
   $db->sql_freeresult($result);
   $topicname = filter($row[topicname], "nohtml");
   $topicimage = filter($row[topicimage], "nohtml");
   $topictext = filter($row[topictext], "nohtml");

$sql = "SELECT sid, title, time, aid, counter, topic, hometext, comments FROM ".$prefix."_stories ORDER BY sid DESC LIMIT 0,10";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) {
    $sid = intval($row['sid']);
    $title = $row['title'];
    $time = $row['time'];
    $aid = $row['aid'];
    $counter = $row['counter'];
   $comments = ($row['comments']);
   $topic = intval($row['topic']);
   $hometext = strip_tags($row['hometext']);
   
$sql2 = "SELECT topicname, topicid FROM ".$prefix."_topics WHERE topicid='$topic' LIMIT 0,10";
$result2 = $db->sql_query($sql2);
$row = $db->sql_fetchrow($result2);
   $topicname = $row['topicname'];
   $datetime= formatTimestamp($time);
   $i = ($i > 1 ? '0' : $i );
   $loopedBG = ($i > 0 ? Bgn1 : Bgn2 );
   $content .= "<div style='background-color: $loopedBG; height:66px; margin:0px 0px 3px 0px; border-bottom:1px dotted #cccccc;'>";
   //if(file_exists($imagepath."topics/$topicimage")) { $topicpath = $themepath; }
    $content .= "<div style='float:left; width:60px; padding:0px 3px 0px 0px;'><a href='modules.php?name=News&amp;file=article&amp;sid=$sid'><img src=\"".$topicpath."images/topics/$topicimage\" title=\"$topictext\" /></a></div>";
    $content .= "<a href=\"modules.php?name=News&file=article&sid=$sid\" ;return false\">$title</a><br /><span class='tabbedDate'>$datetime<br />";
   if (strlen($hometext) > 50)
   $hometext = substr($hometext, 0, 190)."..." ;
   $content .= "$hometext";
   $content .= "<br /><span class='tabbedComment'><a href=\"modules.php?name=News&file=article&sid=$sid\">($comments) "._COMMENTS."</a> - ($counter) "._READS."</span>";
   $content .= "</div>";
   $i++;   
}


So far for some reason only the topicimage 2 appears for all news but each news should match its topic image according to the topic association it falls under
 
View user's profile Send private message
gotcha
Site Admin
Site Admin



Joined: Oct 25, 2004
Posts: 921

PostPosted: Sat May 12, 2007 11:03 pm
Reply with quote

Try changing this part
Code:
<img src=\"".$topicpath."images/topics/$topicimage\" title=\"$topictext\" />


to

Code:
<img src=\"".$tipath."/$topicimage\" title=\"$topictext\" />


$tipath is in the config.php and is set to images/topics by default
 
View user's profile Send private message Visit poster's website
MASsIVE




Joined: Mar 25, 2007
Posts: 27

PostPosted: Sat May 12, 2007 11:31 pm
Reply with quote

Hi gotcha

Thanks for repying

The same results happen only certain image appears for the topics, seems like topicid 2

What im trying to achieve is last 10 news entries from all categories with the matching topic image from the last 10 entries.

Im thinking it has something to do with the sql statement??

Code:
$result = $db->sql_query("SELECT t.topicname, t.topicimage, t.topictext FROM ".$prefix."_stories s LEFT JOIN ".$prefix."_topics t ON t.topicid = s.topic WHERE t.topicid = s.topic");


But it looks like it should work but the results are only one image its coming from topic 2.


For other tabs I want just the last 10 of a single topic this one being topic4 does this appear to have flaws in it??

php:
 $result_t $db->sql_query("SELECT topicid, topicimage FROM " $prefix "_topics WHERE topicid=4");
    
$row_t $db->sql_fetchrow($result_t);
    
$topicimage = ($row_t['topicimage']);
$sql "SELECT sid, title, time, aid, counter, topic, hometext, comments FROM ".$prefix."_stories WHERE topic=4 ORDER BY sid DESC LIMIT 0,10";
$result $db->sql_query($sql);
while (
$row $db->sql_fetchrow($result)) {
    
$sid intval($row['sid']);
    
$title $row['title'];
    
$time $row['time'];
    
$aid $row['aid'];
    
$counter $row['counter'];
    
$comments = ($row['comments']);
    
$topic intval($row['topic']);
    
$hometext strip_tags($row['hometext']);
    
$sql2 "SELECT topicname, topicid FROM ".$prefix."_topics WHERE topicid='$topic' LIMIT 0,10";
$result2 $db->sql_query($sql2);
$row $db->sql_fetchrow($result2);
    
$topicname $row['topicname'];
    
$datetimeformatTimestamp($time);
    
$i = ($i '0' $i );
    
$loopedBG = ($i Bgn1 Bgn2 );
    
$content .= "<div style='background-color: $loopedBG; height:66px; margin:0px 0px 3px 0px; border-bottom:1px dotted #cccccc;'>";
    
$content .= "<div style='float:left; width:60px; padding:0px 3px 0px 0px;'><a href='modules.php?name=News&file=article&sid=$sid'><img src=\"".$tipath."/$topicimage\" title=\"$topictext\" /></a></div>";
    
$content .= "<a href=\"modules.php?name=News&file=article&sid=$sid\" ;return false\">$title</a><br /><span class='tabbedDate'>$datetime<br />";
    if (
strlen($hometext) > 50)
    
$hometext substr($hometext0190)."..." ;
    
$content .= "$hometext";
    
$content .= "<br /><span class='tabbedComment'><a href=\"modules.php?name=News&file=article&sid=$sid\">($comments) "._COMMENTS."</a> - ($counter) "._READS."</span>";
    
$content .= "</div>";
    
$i++;
    


I have a total of 9 tabs tab 2-9 being same code tab 1 being last 10 from all topics so I have duplicated the code 9 times... is there a cleaner easier way to do this ??
Im thinking maybe the code for tabs 2-9 have errors since when I mouseover all the images in tabs 2-9 the topic text from topic 2 appears in all images for all tabs??

Any ideas ? Im stumped now maybe the code needs cleaned up or a function needed?
This is all on big block hahahaa
 
View user's profile Send private message
gotcha
Site Admin
Site Admin



Joined: Oct 25, 2004
Posts: 921

PostPosted: Mon May 14, 2007 8:36 pm
Reply with quote

well instead of copying the same code 9 times, try something like this...

create an array of topic_id's

php:
 $topic_array = array(1,3,5,7,21); 


Then loop through the array and replace the hard coded topic_id with a variable like so...

php:
 foreach($topic_array as $current_topic_id){

// use $current_topic_id in place of the hard coded one
// put your code here



try it out, you'll have lots of fun Smile
ps: try the php bbcode button for longer blocks of code, makes it easier to read
 
View user's profile Send private message Visit poster's website
MASsIVE




Joined: Mar 25, 2007
Posts: 27

PostPosted: Mon May 14, 2007 9:37 pm
Reply with quote

Woah

baby steps hahahaaa

Would that loop for the each? or would I still be duplicating the rest of code?

Exactly how this would integrate with rest of code Im stumped on, any leads Smile
 
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 5 Hours
Forums ©