dongmo6937 2011-10-07 01:07
浏览 14
已采纳

用于不同页面的循环

I'll try to explain the situation as clearly as I can. I've got a system in place that presents links to events, created with JEvents for those familiar(in Joomla)

When an event is created in the admin, the category view for it displays a little table, with the event`s date, name, and a link to the event page. All that works fine. Now the link is called on a separate php file than the one that renders the html view for it all. The link is called with this:

<a class="ev_link_row" href="<?php echo $rowlink; ?>" <?php echo $args;?> style="font-weight:bold;color:<?php echo $fgcolor;?>;" title="<?php echo JEventsHTML::special($row->title()) ;?>"><?php echo $tmpTitle ;?></a> 

On the html rendering script, I've got this:

$this->viewEventRowNew ( $row,'view_detail',JEV_COM_COMPONENT, $Itemid);

Which is comprised in a for loop above, populating the $row variable with all sorts of info.

for( $r = 0; $r < $num_events; $r++ ){
    $row = $data['rows'][$r];

etc.

Now to the question. I've got a table that stores imagefile names. I have no trouble creating a forloop that goesthrough the rows and returns the path name to the images, like this:

$db = & JFactory::getDBO();
$query2 = "SELECT `c`.`filename` AS `iname` , `c`.`filetitle` AS `ititle` , `c`.`ev_id` AS `eventid` FROM `#__jev_files` AS `c` ";
$db->setQuery($query2);
$imagelist = $db->loadObjectList();
?>
  <?php foreach($imagelist as $row) : ?>
 <img src="/images/stories/jevents/<?php echo $row->iname; ?>" />
<?php endforeach; ?>

Now the obvious question, how do I assign this image to be comprised in the link. I tried wrapping the for loop around the linkitself, but it obviously breaks hell as it is reused in a loop(creating a loop within a loop and destroying my layout) If I use the query in the html-rendering page, then my problem is essentially that I do not know how to append the above to the $row variable without breaking the rest of the functionality.

Thanks, a LOT to anyone who can guide me on this.

  • 写回答

1条回答 默认 最新

  • doupaoyan6083 2011-10-07 01:31
    关注

    I think I could give just the answer you're looking for if I could understand the question better. Perhaps some of what you're saying is Joomla-specific so I don't quite get it.

    But generally, object-oriented programming is a good way to keep information about one related thing together, such as all date, description, and collection of images associated with one event. If you can loop through a set of id's and each ID can be used to create an Event object, then each Event object can be made to retrieve it's own information and related images. It keeps code like this cleaner.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?