I need help on a new problem. On my women’s golf club web site I have a Members Directory page which consists of a table, 5 columns in width, and enough 2 rows sets to hold the members photo in the odd numbered rows with the members name in the even numbered rows. Visually it looks like;

table1.jpg

We currently have around 53 members which means the table contains 22 individual rows (11 sets of 2 rows). The directory is sorted by last name, so when ever a new member joins a laborious cut and paste process takes place to get the new member into her proper sorted position. If the new members last name is Williams it’s not to bad but if her name is Connor… it’s a lot of work.

So I have written the following code to automate the process which generates an up-to-date sorted Members Directory page each time it is visited.

if($dbSuccess)
  {
$activeMembers_SQLselect = 'SELECT CONCAT(FirstName," ",LastName) AS name, Picture ';
$activeMembers_SQLselect .= 'FROM ';
$activeMembers_SQLselect .= 'members ';
$activeMembers_SQLselect .= 'WHERE Status = "Active" ';
$activeMembers_SQLselect .= 'ORDER BY LastName , FirstName';

$activeMembers_SQLselect_Query = mysqli_query($dbConnected,$activeMembers_SQLselect);   

$records = mysqli_num_rows($activeMembers_SQLselect_Query);
$set = 2;                               //  Number of rows to display picture and name
$tblColumns = 5;                        //  Numbr of columns in output table
$s = 0;                                 //  Set counter
$r = 0;                                 //  Row counter
$c = 0;                                 //  Column counter
$sets = Round(($records/$tblColumns)+0.5);      // 1 set is 2 rows odd rows are pictures, even rowes are names  

echo    'Record Count = '.$records;         //  Temp record count
echo    ' 2 row sets = '.$sets;             //  Temp set count

echo    '<hr>';
        $row = mysqli_fetch_array($activeMembers_SQLselect_Query); 
echo    '<table width=700px align=center>';
            For ($s = 1; $s <= $sets; $s++)
              {
                For ($r = 1; $r <= $set; $r++)
              {
echo            '<tr>';
                For ($c = 1; $c <= $tblColumns; $c++)
                {
                  If ($r&1)     // If $r is Odd
                 {
                  $currentPic = $row['Picture'];
echo         '<td width=60px align=left><img width=100 src="../MemberPhotos/'.$currentPic.'"</td>';
                  }
                else            //  $r is Even
                  {
                    $currentName = $row['name'];
echo            '<td width=240px align=left><strong>'.$currentName.'</strong></td>';
                  }
              }                 //  For $c
echo            '</tr>';
          }                     //  For $r
        }                       //  For $s
echo    '</table>'; 
echo  '<hr>';

The above code does output a table with 5 columns and 11 sets of 2 rows as it should...HOWEVER, it's the first record's picture and name throughout. I am not moving through the records. Please help.

First you should use HTML and css to play with odd and even.

You are asking only for one row so you can display only one.
Try this:

$rows = [];
while($row = $activeMembers_SQLselect_Query->fetch_array())
{
    $rows[] = $row;
}

var_dump($rows);

Good luck

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.