Forum Moderators: coopster
any ideas and help would be great
regards
Danny
<?php
//handles the listing of featured properties
$result = mysql_query("SELECT * FROM homes WHERE featured = 'Y';",$link);
while ($a_row =mysql_fetch_array ($result) )
{
//add commas to price
$a_row[price] = number_format ($a_row[price]);
print "<td align=\"center\">";
print "<a href=\"./propview.php?view=$a_row[id]\"><b><span class=\"welcomtext\">$a_row[title]</span></b></a><BR>";
//select images connected to a given listing
$query = "SELECT * FROM tbl_files WHERE prop_num = $a_row[id] LIMIT 1";
$output = mysql_query("$query",$link);
$count = 0;
while ($image_row =mysql_fetch_array ($output) )
{
print "<a href=\"propview.php?view=$a_row[id]\">";
if ($useGDimg == 1)
{
print "<img src='$homesimgdir"."tn_"."$image_row[prop_num]$image_row[filename]' border=\"1\" width=\"$homeimgw\" alt=\"Photo\" title=\"Click here to discover more about $a_row[title]\" style=\"border: 1px solid #8b0304;\"></a><br>";
}
if ($useGDimg == 0)
{
print "<img src='$homesimgdir$image_row[prop_num]$image_row[filename]' border=\"1\" width=\"$homeimgw\" alt=\"Photo\" title=\"Click here to discover more about $a_row[title]\" style=\"border: 1px solid #8b0304;\"></a><br>";
}
$count++;
}
if ($count == 0)
{
print "<a href=\"./propview.php?view=$a_row[id]\"><img src=\"./images/nophoto.gif\" border=\"0\" width=100 alt=\"View Listing\" style=\"border: 1px solid #8b0304;\"></a><br>";
}
print "$a_row[beds] beds/$a_row[baths] baths<BR>";
print "$currency$a_row[price]";
print "</td>";
}
// new row after 3
echo "<tr>"; // so I start my row before I enter the loop
$count = 0;
while($row = mysql_fetch_assoc($result))
{
$count++;
if ( ($count % 3) == 0)
{
echo "</tr><tr>"; // we close the current row and start another one
}
echo "<td>cell data</td>";
}
// now we need to create the empty cells to fill out the last row
$filled_cells = $count % 3;
for ($i=$filled_cells; $i<3; $i++)
{
echo "<td> </td>";
}
// finally we close our last row
echo "</tr>";
?>
I think i would change the last bit from:
while($row = mysql_fetch_assoc($result))
{
$count++;
if ( ($count % 3) == 0)
{
echo "</tr><tr>"; // we close the current row and start another one
}
echo "<td>cell data</td>";
}
// now we need to create the empty cells to fill out the last row
$filled_cells = $count % 3;
for ($i=$filled_cells; $i<3; $i++)
{
echo "<td> </td>";
}
to:
while($row = mysql_fetch_assoc($result))
{
if ($count == 3)
{
echo "</tr><tr>"; // we close the current row and start another one
$count = 0";
}
echo "<td>cell data</td>";
$count++;
}
// now we need to create the empty cells to fill out the last row
while ($count <= 3)
{
echo "<td> </td>";
$count++;
}
try changing if ($count == 3) to if ($count == 2) like this:
while($row = mysql_fetch_assoc($result))
{
if ($count == 2)
{
echo "</tr><tr>"; // we close the current row and start another one
$count = 0";
}
echo "<td>cell data</td>";
$count++;
}
// now we need to create the empty cells to fill out the last row
while ($count <= 3)
{
echo "<td> </td>";
$count++;
}
it is the modulus
[php.net...]
danny_s, should that "after 3" code be in the while that starts here
while ($a_row =mysql_fetch_array($result)) {
because it isn't, I also don't see the point to this
while($row = mysql_fetch_assoc($result)) {
unless there is another big loop outside of all of the code that you did not post
let me be sure I understand the logic
1. main query grabs featured listings
2. we start the main loop - while ($a_row =mysql_fetch_array($result)) {
3. start td
4. we grab images for the listing and then do some stuff for them
5. close td
6. end main loop
that is how the braces are matched, I am assuming that you should extend the ending brace there to incorporate your "close row and start new row" logic
put things in the code like
echo '<p>#: ',$count;
or
echo '<p>I got to loop 2';
stuff like that so that it outputs data to the screen and you can know where it is dying
maybe iot fgoes through the whole first while loop and all of the featured listings with out even touching your 3rd cell code
that would mean the 3rd cell code is in the wrong place