| Author |
Message |
MASsIVE

Joined: Mar 25, 2007
Posts: 27
|
Posted:
Fri May 11, 2007 10:51 am |
|
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&file=article&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 |
| |
|
|
 |
gotcha
Site Admin


Joined: Oct 25, 2004
Posts: 921
|
Posted:
Sat May 12, 2007 11:03 pm |
|
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 |
| |
|
|
 |
MASsIVE

Joined: Mar 25, 2007
Posts: 27
|
Posted:
Sat May 12, 2007 11:31 pm |
|
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'];
$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;'>";
$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($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++;
}
|
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 |
| |
|
|
 |
gotcha
Site Admin


Joined: Oct 25, 2004
Posts: 921
|
Posted:
Mon May 14, 2007 8:36 pm |
|
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
ps: try the php bbcode button for longer blocks of code, makes it easier to read |
| |
|
|
 |
MASsIVE

Joined: Mar 25, 2007
Posts: 27
|
Posted:
Mon May 14, 2007 9:37 pm |
|
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  |
| |
|
|
 |
|
|