#1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    15
    Rep Power
    0
    I need to output data into a row of column heads (Left to right). Instead of the common top to bottom.
    Anyone know how to do this using the While statment?
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,646
    Rep Power
    4492
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <table>
    <tr>
    <?
    while ($row = mysql_fetch_array($result)
    {
    echo "<td>$row[column_name]</td>n";
    }
    ?>
    </tr>
    </table>
    [/code]

    That makes it horizontal instead of vertical.

    ---John Holmes...

    ------------------
    *************************************************************
    * The manual can probably answer 90% of your questions...
    *
    * PHP Manual. www.php.net/manual
    * MySQL Manual: www.mysql.com/documentation/mysql/bychapter
    *************************************************************
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    Make it like John did, with the <tr> and </tr> outside the while loop
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    Make it like John did, with the <tr> and </tr> outside the while loop
  8. #5
  9. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    15
    Rep Power
    0
    Yea. I just deleted my last reply. I reviewed his code again and found out where I made my mistake. It works now. You guys kick ***.

    Yea the manual can give me my answers, but this kick *** board is much much faster.
  10. #6
  11. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    15
    Rep Power
    0
    This is great. I am now 2/3rds complete. My last question is, (I hope this can be done) How can I run another query in the same page that will use the output of $row[name] as the key?

    So now I have text outputting:

    |John|Dave|Steve| <--Left Right-->

    Now I need to run a query on the "|John|Dave|Steve|" column results. Like I want add a query on John, that will spool out info about him below his name, then for Dave and Steve. Like this:

    |John|Dave|Steve|
    -----------------
    |-Age|-Age|-Age-|

    I hope all that makes sense. Thanks for all the help!!

    while ($row = mysql_fetch_array($result))
    {
    echo " <td align=center bgcolor=#ECDFC1>$row[name]</td>n";
    }


  12. #7
  13. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    15
    Rep Power
    0
    I need something like this, I know this is completely wrong, but I need something equivalent:

    $query = "select * FROM orgtest WHERE patron = '$row[name]'";

    I will need to run a query like this for every column head that is generated in the previous query.

    [This message has been edited by Rolemaster (edited November 21, 2000).]
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    Two options why not just select both the name and age in one query and simply print the age under the name using a <br> after the name

    <table>
    <tr>
    <?
    while ($row = mysql_fetch_array($result)){ echo "<td>$row[namefiled]<br>$row[agefield]</td>n";
    }
    ?>
    </tr>
    </table>


    Or read the results in to an array then print a row of the names then a row of the ages.

    while ($row = mysql_fetch_array($result)){
    $array[] = array("name" => $row[namefield],
    "age" => $row[agefield];
    }

    <table>
    <tr>
    <?
    for($i=0;$i<count($array);$i++){ echo "<td>$array[$i]["name"]</td>n";
    }
    ?>
    </tr>
    reset($array);
    <tr>
    <?
    for($i=0;$i<count($array);$i++){ echo "<td>$array[$i]["age"]</td>n";
    }
    ?>
    </tr>


    </table>
  16. #9
  17. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    15
    Rep Power
    0
    This is a perfect example of a mere mortal walking into the land of the programming gods. I am obviously a newbie programmer so I do not completely understand what your code will do. I will take some time to study it though.

    I think I wasnt clear before in terms of what I need:

    |John|Dave|Steve| <---Pulled from Patron field in previous query.
    -----------------
    |Name|Name|Name-|
    |Name|Name|Name-|
    |Name|Name|Name-|

    My database just has two fields:

    Name:
    Patron:

    I need to run a query that will pull all the records for people who have the name "john" in their patron field and spool them out under his column. Same for the column under Dave and Steve.

    I am trying to learn as I go....

    [This message has been edited by Rolemaster (edited November 21, 2000).]
  18. #10
  19. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    15
    Rep Power
    0
    I might as well lay it all out:

    ----|Mark| <---Monarch
    |John|Dave|Steve| <---Mark is the patron for these guys.
    -----------------
    |Name|Name|Name-|<---John is the patron for the first column.. etc....
    |Name|Name|Name-|
    |Name|Name|Name-|

    I need to run at least two queries. The first is for the 2nd row to find out who is the patron for mark.

    The 2nd is to output all the names under the columns of |John|Dave|Steve| who have |John|Dave|Steve| as their patron.
  20. #11
  21. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,646
    Rep Power
    4492
    How is your database set up? Is this all in one table, or are the names referenced back to the patrons in another table? This should be able to be done with one query, if you have the right group by and order clauses.

    I would put each patron and their names in a table of their own. If you could get a query that would return the patron and the name, something like this:

    John name1
    John name2
    John name3
    Dave name1
    Dave name2
    Dave name3

    Then something like this should work.
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    $patron = "";
    $old_patron = "old";
    $result = mysql_query("SELECT patron,name FROM your_table");
    $first_time=true;
    while (list($patron,$name) = mysql_fetch_row($result))
    {
    if($patron != $old_patron)
    {
    if(!$first_time)
    { echo "</table>n"; $first_time = false; }
    echo "<table border=0>n";
    echo "<tr><td><b>$patron<b></td></tr>n";
    echo "<tr><td>$name</td></tr>n";
    }
    else
    {
    echo "<tr><td>$name</td></tr>n";
    }
    $old_patron = $patron;
    }
    echo "</table>n";
    ?>
    [/code]
    Or at least I hope it will, if not, hopefully it gives you some ideas.

    ---John Holmes...

IMN logo majestic logo threadwatch logo seochat tools logo