I spit out 4 photos across the screen, then I want to start a new row of the next 4 photos, then so on until done.

This works fine expcet the first row shows only 3, then it goes to 4 across.

Can someone help?

<?php
$ln = $_POST;
$ps = $_POST;
$yg = $_POST;
$cy = $_POST;
$st = $_POST;
$gn = $_POST;
include('admin/mysql.php');
if ($ln != '') {
$query = "select * from tbl_accounts WHERE lastname LIKE '$ln%' ORDER by lastname ASC";
} else if ($ps != '') {
$query = "select * from tbl_accounts WHERE primarysport = '$ps' ORDER by lastname ASC";
} else if ($yg != '') {
$query = "select * from tbl_accounts WHERE yeargraduate = '$yg' ORDER by lastname ASC";
} else if ($cy != '') {
$query = "select * from tbl_accounts WHERE city LIKE '$cy%' ORDER by lastname ASC";
} else if ($st != '') {
$query = "select * from tbl_accounts WHERE state = '$st' ORDER by lastname ASC";
} else if ($gn != '') {
$query = "select * from tbl_accounts WHERE gender = '$gn' ORDER by lastname ASC";
} else {
$query = "select * from tbl_accounts WHERE gender = 'yes'";
echo "<tr><td class=bodytext>Please go back and enter your search criteria.</td></tr>";
}
$result = mysql_query($query);
echo "<tr>";
$count = 0;
while ($row = mysql_fetch_array($result)){
$userID = $row;
$firstname = $row;
$lastname = $row;
$photo = $row;
$yeargraduate = $row;
$profiletype = $row;
$orgname = $row;
$state = $row;
$count++;
if ( ($count % 4) == 0)
{
echo "</tr><tr>"; // we close the current row and start another one
}
if ($photo == '') {
echo "<td class=bodytext width=25%><img src=images/no-photo.jpg width=75 height=100 border=3><br>$firstname $lastname<br>";
} else {
echo "<td class=bodytext width=25%><img src=profile_photos/$photo width=75 height=100 border=3><br>$firstname $lastname<br>";
}
if ($profiletype != 'Individual') {
echo "$orgname<br>$state<br><a href=orgprofile.php?userID=$userID>View Profile</a>";
} else {
echo "$yeargraduate<br>$state<br><a href=player.php?userID=$userID>View Profile</a>";
}
}
echo "</td></tr>";
?>

Recommended Answers

All 3 Replies

$i=0;
while($row=mysql_fetch_array($result)){
$photo=$row['photo'];
if($i==0) { //initially, i is 0, so it inserts a new tr. 
   echo "<tr>";
}
$i++;
echo "<td>$photo</td>"; //add the photo
if($i==4){ //adds 4 photos, once its done, make i as 0 to insert a new <tr>, end the existing <tr>.
  $i=0; 
  echo "</tr>"; 
}
}

Cheers,
Naveen

commented: Awesome!!! +1

Dude, you rock.

Thanks Man, works great.

You are welcome :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.