I want to create a photos gallery displaying on the left all the pictures from a same category and on the right the comment.
The images are stored just as a path (eg: mycategory/example001.jpg
) in my database in the table jkm_image
in the column filename
.
The comment are stored in the table jkm_content
in introtext
.
The two tables aren't related.
I get stuck on the "foreach" step because it retreives first all the image and then all the comment so I end up with something like
an image
an image
an image
...
a comment
a comment
a comment
or
an image, an image, an image
an image, an image, an image
...
a comment, a comment, a comment
a comment, a comment, a comment
but I want :
an image, a comment
an image, a comment
an image, a comment
...
Here's the 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;
}
I'm pretty new to the php world and I don't know if I am doing things right. Maybe the "foreach" isn't the function I should use.
Thanks a lot for your help!