Search engine result, two tables and while problem?
Posted: Fri May 22, 2009 5:09 am
Hello 
I have a php mysql search engine. In database i have two tables, these are houses and images. All the data like house_id, title, content, price is stored in houses table. And then in table images i have columns image_id, house_id, image, image_type (this column has a value main or normal).
Well i actually know how to connect these two tables and how to show all columns in houses table but here is the problem because i only know how to show one image, image that has value "main" in column image_type. The question is, how to show all images, where image_type is same as "main" and same as "normal" and where house_id from table images belongs to house_id in houses table.
Here's the code that i tryed, but doesn't work as i want, it only works for the main picture:
Can someone please tell me what exactly should i do to solve this, cause i have no clue
P.S. --> on some other forum they just told me to create another query and i tryed, but i was probably doing it wrong, i was trying to create while inside while but that is probably wrong, cause i got so many results.
Thank you,
Housy
I have a php mysql search engine. In database i have two tables, these are houses and images. All the data like house_id, title, content, price is stored in houses table. And then in table images i have columns image_id, house_id, image, image_type (this column has a value main or normal).
Well i actually know how to connect these two tables and how to show all columns in houses table but here is the problem because i only know how to show one image, image that has value "main" in column image_type. The question is, how to show all images, where image_type is same as "main" and same as "normal" and where house_id from table images belongs to house_id in houses table.
Here's the code that i tryed, but doesn't work as i want, it only works for the main picture:
Code: Select all
<?php
if(isset($_POST["find"])) {
$sql = "SELECT a.title,
a.content,
a.region,
a.place,
a.parcela,
a.kvadratura,
a.price,
b.house_id,
b.image,
b.image_type
FROM houses AS a,
images AS b
WHERE a.house_id = b.house_id
AND a.region = '".mysql_real_escape_string($_POST["region"])."'
AND b.image_type = '".mysql_real_escape_string("main")."'
ORDER BY house_id DESC";
$res = mysql_query($sql) or die(mysql_error());
$show = mysql_fetch_array($res);
while($show) { ?>
<div class="result">
<div class="result_top_left"></div><div class="result_top"></div><div class="result_top_right"></div>
<div class="result_content">
<div class="picture"><a href="images/houses/<?php print $show["house_id"]."/".$show["image"]; ?>" rel="lightbox"><img src="images/houses/<?php print $show["house_id"]."/thumbs/".$show["image"]; ?>" alt="<?php print $show["title"]; ?>" /></a></div>
<div class="description">
<p class="main_title"><?php print $show["title"]; ?></p>
<?php print $show["region"]; ?> regija, <?php print $show["place"]; ?><br />
Bivalna površina: <?php print $show["kvadratura"]; ?> m<sup>2</sup><br />
Površina parcele: <?php print $show["parcela"]; ?> m<sup>2</sup><br />
Cena: <?php print $show["price"]; ?> €
<p style="float: right; margin: 20px 0px 0px 0px; padding: 0px; border: none"><a href="javascript:void(0);" onclick="shToggle('more'); return false;"><img src="images/more.png" alt="more" /></a></p>
</div>
<div style="display: none" id="more">
<p>OPIS</p>
<?php
print "<p style='border-bottom: 1px black dashed'>".$show["content"]."</p>";
[b]HERE I WANT TO SHOW PICTURES (thumbnails) THAT BELONGS TO THIS house_id AND has value of "normal"[/b]
?>
</div>
</div>
<div class="result_down_left"></div><div class="result_down"></div><div class="result_down_right"></div>
</div>
<?php } } ?>P.S. --> on some other forum they just told me to create another query and i tryed, but i was probably doing it wrong, i was trying to create while inside while but that is probably wrong, cause i got so many results.
Thank you,
Housy
