SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Zealot Jafar's Avatar
    Join Date
    Jun 2005
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    showing records in this format?

    Hi,
    How i can show my records in this format?
    1 8
    2 9
    3 10
    4 11
    5 12
    6 13
    7 14

    Thanks

  2. #2
    SitePoint Evangelist nsj's Avatar
    Join Date
    Oct 2005
    Location
    Jamaica (W.I)
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    records from mysql?

    best way is to use tables

    PHP Code:
    <table>
    <?
    while($row mysql_fetch_object(results)){
         
    $col1 $row->Col1;
         
    $col2 $row->Col2;

         
    ?>
         <tr>
              <td><?=$Col1?></td>
              <td><?=$Col2?></td>
         </tr>
         <?
    }
    ?>
    </table>

  3. #3
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think he wants 1 to 7 vertical, then back up again from 8 to 14.
    Easiest way is to put 1-7 and 8-14 into two different tables and use css to float both of them left, i.e.:

    Code:
    table.floatLeft {
    float: left;
    }
    
    <table class="floatLeft">
    <tr><td>first table</td></tr>
    ...
    </table>
    <table class="floatLeft">
    <tr><td>second table</td></tr>
    ...
    </table>

    With records coming from a db, you'd need to count all records and get the value of half of them: ceil($numrows/2) or somesuch so you'd know when to start the second table.

    Oh, and don't forget to "clear:left" afterwards.

  4. #4
    SitePoint Zealot Jafar's Avatar
    Join Date
    Jun 2005
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mudshark
    I think he wants 1 to 7 vertical, then back up again from 8 to 14.
    Easiest way is to put 1-7 and 8-14 into two different tables and use css to float both of them left, i.e.:

    Code:
    table.floatLeft {
    float: left;
    }
    
    <table class="floatLeft">
    <tr><td>first table</td></tr>
    ...
    </table>
    <table class="floatLeft">
    <tr><td>second table</td></tr>
    ...
    </table>

    With records coming from a db, you'd need to count all records and get the value of half of them: ceil($numrows/2) or somesuch so you'd know when to start the second table.

    Oh, and don't forget to "clear:left" afterwards.
    thx
    but i did not understand!
    for example i have these records:
    record1,record2,record3,record4,record5
    in RECORD field
    i want show in each column 3 records
    how i can do it?

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This code should be useful
    PHP Code:
    <table>
    <tr>
    <?php

    $i
    =1;

    while(
    $i<9)
    {
    echo 
    "<td>".$i."</td>";

    if(
    $i%3==0) echo "</tr><tr>";

    $i++;
    }

    ?>
    </tr>
    </table>
    OOP Addict - sorry for my english

  6. #6
    SitePoint Zealot Jafar's Avatar
    Join Date
    Jun 2005
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by NuLL[PL]
    This code should be useful
    PHP Code:
    <table>
    <tr>
    <?php

    $i
    =1;

    while(
    $i<9)
    {
    echo 
    "<td>".$i."</td>";

    if(
    $i%3==0) echo "</tr><tr>";

    $i++;
    }

    ?>
    </tr>
    </table>
    1 5
    2 6
    3 7
    4 8
    not:
    1 2 3
    4 5 6

  7. #7
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you are not making any sense.. first you show us two columns with 7 records, then you
    say
    i want show in each column 3 records
    how i can do it?
    then you show us that you want 4 records in each column
    1 5
    2 6
    3 7
    4 8
    not:
    1 2 3
    4 5 6

    maybe if you explain what you want a bit better we can help, because right now everyone is just guessing.

  8. #8
    SitePoint Zealot Jafar's Avatar
    Join Date
    Jun 2005
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mwolfe
    you are not making any sense.. first you show us two columns with 7 records, then you
    say
    then you show us that you want 4 records in each column



    maybe if you explain what you want a bit better we can help, because right now everyone is just guessing.
    sorry
    these are just examples
    you suppose N record in Each column(unlimited column)
    number of column depends on number of records and N.
    and N define

  9. #9
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    something like this should work
    Edit:


    see below

  10. #10
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually there are a few small problems in the above example, here is a fixed version

    PHP Code:

    define
    ("N"5); //change this to whatever you want except 0.
    $query "select some_col from some_table";
    $res mysql_query($query);
    $total_rows mysql_num_rows($res);
    $num_cols ceil($total_rows/N);
    echo 
    "<table>\n";
    for (
    $i=0$i<N$i++) {
      echo 
    "<tr>\n";
      for (
    $j=0$j<$num_cols$j++) {
         
    $current=$i + ($j*N);
         if (
    $current $total_rows) {
            
    mysql_data_seek($res$current);
            list(
    $item) = mysql_fetch_row($res);
             echo 
    "<td>$item</td>\n";
         } else {
            echo 
    "<td>&nbsp;</td>\n";
         }
      }
      echo 
    "\n</tr>\n";
    }
    echo 
    "</table>" 
    Last edited by mwolfe; Nov 23, 2005 at 14:01.

  11. #11
    SitePoint Zealot Jafar's Avatar
    Join Date
    Jun 2005
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Quote Originally Posted by mwolfe
    actually there are a few small problems in the above example, here is a fixed version

    PHP Code:

    define
    ("N"5); //change this to whatever you want except 0.
    $query "select some_col from some_table";
    $res mysql_query($query);
    $total_rows mysql_num_rows($res);
    $num_cols ceil($total_rows/N);
    echo 
    "<table>\n";
    for (
    $i=0$i<N$i++) {
      echo 
    "<tr>\n";
      for (
    $j=0$j<$num_cols$j++) {
         
    $current=$i + ($j*N);
         if (
    $current $total_rows) {
            
    mysql_data_seek($res$current);
            list(
    $item) = mysql_fetch_row($res);
             echo 
    "<td>$item</td>\n";
         } else {
            echo 
    "<td>&nbsp;</td>\n";
         }
      }
      echo 
    "\n</tr>\n";
    }
    echo 
    "</table>" 
    Thanks a lot


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
  •