Click to See Complete Forum and Search --> : Need Simple Help Selecting Multiple categories and Limiting Output


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>

chazzy
05-11-2006, 08:44 PM
maybe change these queries


SELECT COUNT(*) FROM `listings` WHERE active=1 AND type='apartment';
SELECT * FROM `listings` WHERE active=1 AND type='apartment' ORDER BY state,city;


to
SELECT COUNT(*) FROM `listings` WHERE active=1 AND (type='apartment' or type='indus');
SELECT * FROM `listings` WHERE active=1 AND (type='apartment' or type='indus') ORDER BY state,city

as for this
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?

Yes it's possible. you just set the size in your tag.

Mr. Waffles
05-11-2006, 09:22 PM
Great! Thanks!

How would I limit it to only outputting 4 images?

chazzy
05-11-2006, 09:38 PM
add LIMIT 4 to the end of your query.

Mr. Waffles
05-11-2006, 10:03 PM
Thanks again. You entirely rock.

Mr. Waffles
05-12-2006, 07:40 PM
How could I make the output random, instead of sorting by state and city?

Mr. Waffles
06-27-2006, 06:23 PM
Another question:

How can I, instead of limiting by number (ie limit 4), limit the output based on the table layout that it falls into??

I would like to have one include page that outputs pictures in a table column that will fill the page downward to the appropriate length, but will not overflow the layout of the containing page.

I have pages with content of varying lengths, but would like the include page to conform to the natural layout of the page...the longer page displays more pictures to fill up the left td.

Is there a way perhaps to do this with just the table, if not the php?

Thanks!