SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As the subject says, how can I print the mysql result in two or more html columns? Do I have to play around with for-loops and the limit? What have or would you have done?

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    while ( $row = mysql_fetch_array($result) ) 
    {    
    
    
    
    print("<tr>
    <td>$row[author]</td>
    <td>$row[title]</td>
    </tr>");
    
    }
    2 columns. No biggee.

    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  3. #3
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Following on to this post, what if you have only one field:

    "category"

    which had to be in too columns??


  4. #4
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx aspen, but this is what I already know what I wanted to do is split the result into columns and then print them. So it may look like the php/cgi category's page of HotScripts. Any idea?

  5. #5
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm what I showed was the results split in 2 columns.. Maybe you need to explain in more detail exactly what it is you want. I looked at hotscripts and don't see what you mean.

    Is it that you want two tables of results side by side?

    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DIMA

    $numcols = 2;
    $count = 1;
    print '<tr>';
    while ($row = mysql_fetch_array($result)) {
    if ($count % $numcols = 0) {
    print '<td>yourdata</td></tr><tr>';
    }
    else {
    print '<td>yourdata</td>';
    }

    $count++;
    }
    print '</tr></table>';
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm.. okay, again: I want to print out the result in at least two columns. For example an index from A to Z. In the first column it should print the first half (A-M) and the second has the other half. Just like the categories at Hotscripts (http://www.hotscripts.com/PHP/Scripts_and_Programs/). So it's not a long list of categories but instead split up in two parts.

    How can I do that in PHP? I'm thinking of working with LIMIT in the sql-query...

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe its you that is being unclear!
    $count = 1;
    print '<table border="1"><tr><td>';
    for ($i=1;$i<19;$i++) {
    while ($row = mysql_fetch_array($result)) {
    if ($count == 10) {
    print '</td><td>yourdata<br>';
    }
    else {
    print 'yourdata<br>';
    }
    $count++;
    }
    print '</td></tr></table>';
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks! That's what I needed Sorry, for being not precise...

  10. #10
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DIMA is making two columns with two different fields. How would i put two colums with one field? Making sure that data is repeated.

    Example
    -----------------------
    |Bob | Jack |
    |Peter | Jill |
    |Jane | Henry |
    |Mike | Jemima |
    -----------------------

    ?

  11. #11
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use my first post on this subject
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  12. #12
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using your first post i get:

    http://www.codingclick.com/subcats.php?cid=1

  13. #13
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is my first post see it a little further up from where you tried
    DIMA

    $numcols = 2;
    $count = 1;
    print '<table><tr>';
    while ($row = mysql_fetch_array($result)) {
    if ($count % $numcols = 0) {
    print '<td>yourdata</td></tr><tr>';
    }
    else {
    print '<td>yourdata</td>';
    }

    $count++;
    }
    print '</tr></table>';

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  14. #14
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  15. #15
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can we see the code you used to create that? Its a little hard to debug things when only seeing the output to the screen
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  16. #16
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    print "<table border='1'><tr>";
    $numcols = 2;
    $count = 1;
    print "<tr>";
    while ($cat = mysql_fetch_array($write)) {
    $id = $cat["ID"];
    $name = $cat["SubCat"];
    $cid = $cat["CID"];
    $description = $cat["Description"];
    if ($count % $numcols = 0) {
    print "<td><p><a href='list.php?cid=$cid&sid=$id'><font size='+1'><b>$name</b></font></a> " .
    "<br><font size='1'>$description</font></td></tr><tr>";

    }
    else {
    print "<td><p><a href='list.php?cid=$cid&sid=$id'><font size='+1'><b>$name</b></font></a> " .
    "<br><font size='1'>$description</font></td>";

    }
    $count++;

    }
    print "</tr></table>";

  17. #17
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try
    if ($count % $numcols == 0) {
    instead of
    if ($count % $numcols = 0) {

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  18. #18
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's it.

    Thanx allot.

    This one is going into the records. Brilliant script.


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
  •