我想创建一个照片库,左侧显示同一类别的所有图片,右侧显示评论。mycategory/example001.jpg
图像在我的数据库中jkm_image
的列中的表中存储为路径(例如 :) filename
。评论存储在表jkm_content
中introtext
。
这两个表不相关。
我被困在“foreach”步骤上,因为它首先检索所有图像,然后检索所有评论,所以我最终得到类似
an image
an image
an image
...
a comment
a comment
a comment
或者
an image, an image, an image
an image, an image, an image
...
a comment, a comment, a comment
a comment, a comment, a comment
但我想要 :
an image, a comment
an image, a comment
an image, a comment
...
这是php:
<?php
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
$db = &JFactory::getDBO(); //Your database object is ready
$db2 = &JFactory::getDBO();?>
<div class="backend">
<?php
$query = "SELECT introtext FROM jkm_content WHERE catid=58"; //--------feeds
$db->setQuery( $query );
$feeds= $db->loadObjectList();
foreach ($feeds as $item):
?>
<div class="comment"><?php echo $item->introtext; ?></div>
<?php endforeach; ?>
<?php
$query2 = "SELECT filename FROM jkm_phocagallery WHERE catid=2";// -------pictures
$db2->setQuery( $query2 );
$pictures= $db2->loadObjectList();
foreach ($pictures as $item2):
?>
<div class="image"><img src="/images/phocagallery/<?php echo $item2->filename; ?>" >
</div>
<?php endforeach; ?>
</div>
CSS:
.backend {
position: absolute;
width: 1000px;
}
.image {
float:left;
width: 600px;
}
.comment {
float:right;
width: 400px;
}
我对 php 世界很陌生,我不知道我是否做对了。也许“foreach”不是我应该使用的功能。
非常感谢你的帮助!