Mr. Waffles
05-11-2006, 06:36 PM
I'm a newbie, and I'm working with pieces of existing code.
I'm trying to display a limited number of random pictures from a mySQL database found in a directory on my site.
1) The existing code collects data from 'type'='apartment' but I'd like it to also display the 'type'='indus' as well. What is the proper syntax to include a second 'type' of listing?
2) Also, I want to limit the output to either a specific number of images, like four instead of listing all, or to display in a specific ammount of vertical space, like 600 pixels. Really so that it fits into the window of my page without expanding the page size. Is this possible?
Thanks!
Here is the code:
<? php ?>
<html>
<body>
<table width="380" border=0>
<tr><?
$file_dir="./listings";
require ("sql.inc");
$f = mysql_pconnect("localhost","database","password");
// valid types = { indus , apartment , landdev , rvrec }
$result = mysqlquery("webworks_mri","SELECT COUNT(*) FROM `listings` WHERE active=1 AND type='apartment'");
$listings = mysql_result($result,0,0);
$result = mysqlquery("webworks_mri","SELECT * FROM `listings` WHERE active=1 AND type='apartment' ORDER BY state,city");
$i=0;
while ($row=mysql_fetch_array($result)) {
if ($i%1==0) {
echo "</tr><tr>";
}
echo "<td align=center width=50%>";
echo "<a href=\"$file_dir/" . $row['pdf'] . "\"><img src=\"$file_dir/" . $row['image'] . "\" alt=\"" . $row['name'] . "\" class='phppicture'></a><br>\n";
echo '<span class="phpcaption">' . $row['name'] . "<br>\n" . '</span>';
echo '<p class="phpdetails">';
echo $row['city'] . ", " . $row['state'] . "<br>\n";
echo '</p>';
echo "</td>";
$i++;
if ($listings == 1) {
echo "<td width=50%> </td>";
}
$listings--;
}
?></tr>
</table>
</body>
</html>
I'm trying to display a limited number of random pictures from a mySQL database found in a directory on my site.
1) The existing code collects data from 'type'='apartment' but I'd like it to also display the 'type'='indus' as well. What is the proper syntax to include a second 'type' of listing?
2) Also, I want to limit the output to either a specific number of images, like four instead of listing all, or to display in a specific ammount of vertical space, like 600 pixels. Really so that it fits into the window of my page without expanding the page size. Is this possible?
Thanks!
Here is the code:
<? php ?>
<html>
<body>
<table width="380" border=0>
<tr><?
$file_dir="./listings";
require ("sql.inc");
$f = mysql_pconnect("localhost","database","password");
// valid types = { indus , apartment , landdev , rvrec }
$result = mysqlquery("webworks_mri","SELECT COUNT(*) FROM `listings` WHERE active=1 AND type='apartment'");
$listings = mysql_result($result,0,0);
$result = mysqlquery("webworks_mri","SELECT * FROM `listings` WHERE active=1 AND type='apartment' ORDER BY state,city");
$i=0;
while ($row=mysql_fetch_array($result)) {
if ($i%1==0) {
echo "</tr><tr>";
}
echo "<td align=center width=50%>";
echo "<a href=\"$file_dir/" . $row['pdf'] . "\"><img src=\"$file_dir/" . $row['image'] . "\" alt=\"" . $row['name'] . "\" class='phppicture'></a><br>\n";
echo '<span class="phpcaption">' . $row['name'] . "<br>\n" . '</span>';
echo '<p class="phpdetails">';
echo $row['city'] . ", " . $row['state'] . "<br>\n";
echo '</p>';
echo "</td>";
$i++;
if ($listings == 1) {
echo "<td width=50%> </td>";
}
$listings--;
}
?></tr>
</table>
</body>
</html>