SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Output to columns php mysql

    Hello all,

    i have this code that display results in the format

    Department A
    user1
    user2
    user3
    Department B
    user1
    user2
    user3

    below is my code, i have a table called staff departments with the fields dep_id and dep_name and a table for users that holds the staff_departent name;

    Code:
    PHP Code:
    <?
    include "inc/staffdirectory.php";
    $result = @mysql_query("SELECT DISTINCT dep_name from staff_departments ORDER BY dep_name ASC");
    While(
    $row = @mysql_fetch_array($result)) {
    echo 
    "<strong>$row[dep_name]</strong><br>"// Category A, B, etc...
    $result2 = @mysql_query("SELECT staff_name, staff_lastname, staff_title, staff_phone from users where staff_office = '$row[dep_name]'");
    While(
    $row2 = @mysql_fetch_array($result2)) {
    echo 
    "$row2[staff_name]";
    echo 
    " ";
    echo 
    "$row2[staff_lastname]";
    echo 
    " ";
    echo 
    "$row2[staff_title]";
    echo 
    " ";
    echo 
    "$row2[staff_phone]<br>";
    //End Product Loop
    // End Category Loop}
    ?>

    My question is, how can i make it display the results in the format (columns)

    Department A | Department B

    and the users under each department

    thanks for any help in advance.

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?
    include "inc/staffdirectory.php";
    $result = @mysql_query("SELECT dep_name, staff_name, staff_lastname, staff_title, staff_phone FROM staff_departments JOIN users ON staff_office=dep_name ORDER BY dep_name ASC");

    $deps=array();

    While(
    $row = @mysql_fetch_array($result)) {
        if(!
    in_array($row['dep_name'],$deps)){
              if(
    count($deps)!=0) echo '</div>';
            echo 
    '<div style="float:left;margin:0 10px">';
            
    $deps[]=$row['dep_name'];
            echo 
    "<strong>$row[dep_name]</strong><br>"// Category A, B, etc...
        
    }
        echo 
    "$row2[staff_name]";
        echo 
    " ";
        echo 
    "$row2[staff_lastname]";
        echo 
    " ";
        echo 
    "$row2[staff_title]";
        echo 
    " ";
        echo 
    "$row2[staff_phone]<br>";
    // End Category Loop}

    echo '</div><br style="clear:both" />';
    ?>
    Saul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •