Forum Moderators: coopster
<?php
$query = mysql_query("SELECT * FROM classifieds
LEFT JOIN img ON img.classified_id = classifieds.id
LEFT JOIN state ON classifieds.state_id = state.id
LEFT JOIN city ON classifieds.city_id = city.id WHERE id = '".$id."' AND
authorized = '1'
");
while($row = mysql_fetch_array($query, MYSQL_ASSOC))
{
?>
<div align="center"><a href=' <?php echo $row['image_path']; ?>' rel='lightbox'
title='<?php echo $row['title']; ?>' style='text-decoration:none;'> <img
src='<?php echo $row['image_path']; ?>' width='150' border='0' />
</a>
</div>
<div class="show_location" style="width:225px; hight:10px; padding-top:20px;">
<span class='style55'><?php echo $lang['D_STATE']; ?> <span style="color:#06F">
<?php echo $row['statename']; ?></span> </div>
<div style="width:225px; hight:10px; padding-top:20px;"> <?php echo
$lang['D_CITY']; ?><span style="color:#06F"> <?php echo $row['city']; ?></span>
</span> </div>
<?php
}
?>
Davidkarate wrote:
I got everything working with this query, except the result is repeating user information for every image.
<?php
$result = mysqli_query( "SELECT `classifieds`.`title`, `classifieds`.`description`, `state`.`statename`, `city`.`city`
FROM `classifieds`
LEFT JOIN `state` ON `classifieds`.`state_id` = `state`.`id`
LEFT JOIN `city` ON `classified`.`city_id` = `city`.`id`
WHERE `classifieds`.`id` = " . $id . "
AND `authorized` = '1'" );
$classified = mysqli_fetch_assoc( $result );
$result = mysqli_query( "SELECT `image_path` FROM `img` WHERE `classified_id` = " . $id );
$classified['images'] = array();
while( false !== ( $row = mysqli_fetch_assoc( $result ) ) {
$classified['images'][] = $row;
}
var_dump( $classified );
?>
$id is properly sanitized or you open yourself up to SQL injection attacks. This can't be stressed enough.