Static Column amongst Multi-Column Loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LuiePL
    New Member
    • Sep 2006
    • 24

    Static Column amongst Multi-Column Loop

    I'm looking to update my member list, Since certain states will have more members, I've decided to go with a "single list" approach. I found the following code from this site, which I have modified for my purposes:

    [PHP]$columns = 3;

    $query = Non Admins;
    $result = mysql_query($qu ery);

    $num_rows = mysql_num_rows( $result);

    //we are going to set a new variables called $rows
    $rows = ceil($num_rows / $columns);

    //to do this display, we will need to run another loop
    //this loop will populate an array with all our values
    while($row = mysql_fetch_arr ay($result)) {
    $data_row = $row['Number'].'-'.$row['FirstName'].' '.$row['LastName'];
    $data[] = $data_row;
    }

    echo "<TABLE BORDER='0'>\n";

    echo "<tr>\n<td valign='top' width='25%'>\n" ;

    $querymem = Admins;
    $sqlmem = mysql_query($qu erymem) or die(mysql_error ());

    while ($rowmem = mysql_fetch_arr ay($sqlmem))
    {
    $number = $rowmem['Number'];
    $fullname = $rowmem['FirstName']." ".$rowmem['LastName'];
    echo "<p><b><fon t color='#FFCC00' ><a href='member.ph p?name=$number' >".strtoupper($ number)."</a></font></b><br />".ucwords($ful lname)."</p>\n";
    }

    echo "</td>\n</tr>\n";

    //here we changed the condition to $i < $rows
    for($i = 0; $i < $rows; $i++) {

    echo "<TR>\n";

    //here will run another loop for the amount of columns
    for($j = 0; $j < $columns; $j++) {
    if(isset($data[$i + ($j * $rows)])) {
    $member_info = explode("-", $data[$i + ($j * $rows)]);
    $number = $member_info[0];
    $name = $member_info[1];
    echo "<TD valign='top' width='25%'>";
    echo "<b><a href='member.ph p?name=$number' >".strtoupper($ number)."</a></b>";
    echo "<br />".ucwords($nam e);
    echo "</TD>\n";
    }
    }
    echo "</TR>\n";
    }
    echo "</TABLE>\n";[/PHP]

    You can see the results on my test page. So I'm trying to figure out a way to still have the one column for administrators only, and the regular members to be in the other columns.
  • bevort
    New Member
    • Jul 2006
    • 53

    #2
    You could try to put all in one 2D array with 3 colomns per row filling the first colomn with the admins and the 2nd and 3rd witn you members
    Then, when creating the HTML, use the array instead of the queries

    Comment

    Working...