I agree with Jochem that you can grab the exact data in one query. However,
after seeing the problem from another perspective, your problem lies at the
fact that you directly used $pic to print the image name:
$pic = mysql_query("select img_name from pics WHERE rntID = 31");
echo "$pic <br>";
echo "<img src=\"../images/$pic\" />";
You must either use mysql_fetch_array() or mysql_fetch_object() first (there
are other ways, but I prefer the latter) because $pic contains the result of
your query-- not the data contained in the fields of the current row.
Therefore, the correct way to print the contents of img_name is:
$data = mysql_fetch_object($pic)
echo "$pic->img_name <br />";
echo "<img src=\"../images/$pic->img_name\" />";
or, using mysql_fetch_array():
$data = mysql_fetch_array($pic)
echo $pic["img_name"] . "<br />";
echo "<img src=\"../images/{$pic['img_name']}\" />";
Regards,
[ simon.cpu ]
>
>This is a Cartesian product that is subsequently LIMITed. Is that
>intentional?
>
>
>> // format results by row
>> while ($row = mysql_fetch_array($result)) {
>> $id = $row["ID"];
>> $pic = mysql_query("select img_name from pics WHERE rntID = 31");
>
>I don't fully understand the logic, but can't you just grab the
>exact data you need in one query?
>
>SELECT rnt.ID, pics.img_name
>FROM Rentals rnt INNER JOIN pics ON rnt.ID = pics.rntID
>WHERE featured = 1
>ORDER BY RAND()
>LIMIT 1
>
>Jochem
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking
application. Start tracking and documenting hours spent on a project or with a
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:208026
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54