SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to display data in columns?

    Hello everyone!! I am sorry for my english. I hope you could understand.
    More or less I want to display like a this table but I have a problem. My table has got 5 colums(tds) and 3 rows(tr) that takes data from mysql database.

    I use foreach and i can get the data. But when I want to display like I told before, 5 colums and 3 rows, my css layout change, getting all data in one row. How could I display this kind of data ? What I want is that when fills 5 colums, get the next row.

    Thank You Very Much

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,501
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Could you post the code with the foreach that displays the data?

  3. #3
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello! Thank you for answering my question. I couldnīt answer before.
    I have this code but it doesnīt work at all.
    <table>

    <?php

    $cols=5;
    $rows=3;
    foreach ($jokes as $joke): ?>

    <?php
    $ordu=htmlspecialchars($joke['ordu'],ENT_QUOTES, 'UTF-8');
    $id_erretserba= htmlspecialchars($joke['id_erretserba'],ENT_QUOTES, 'UTF-8');
    $zelan= htmlspecialchars($joke['zelan'],ENT_QUOTES, 'UTF-8');
    $erabi_izena=htmlspecialchars($joke['erabi_izena'],ENT_QUOTES, 'UTF-8');

    $eguna=htmlspecialchars($joke['eguna'],ENT_QUOTES, 'UTF-8');
    $ordua=htmlspecialchars($joke['ordua'],ENT_QUOTES, 'UTF-8');
    $od=htmlspecialchars($joke['ordua'],ENT_QUOTES, 'UTF-8');
    $merabil=htmlspecialchars($joke['merabil'],ENT_QUOTES, 'UTF-8');

    ?>

    <?php

    for ($i=1; $i<=$rows; $i++) {
    echo '<tr>';

    for ($i=1; $i<=$cols; $i++) {

    ?>
    <td>
    <img src="arg/lauki_berde.jpg" />

    <div class="orduak_okupazioa08">
    <div class="orduak_okupazioa_1"><?php echo $ordua; ?></div>

    <div class="orduak_okupazioa_2">libre</div>
    </div>

    <div class="orduak_okupazioa_nork08">Libre</div>
    </td>
    <?php
    }
    echo '</tr>';
    }
    ?>


    <?php endforeach;?>

    </table>

  4. #4
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are use a framework ??

    Ok you can change $i in one of your loops


    for ($r=1; $r<=$rows; $r++) {

  5. #5
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much for answering.
    I wanīt using framework and I changed the variable but it couldnīt work.
    At the end, I got it but not this way. Using a different arrays.
    Thank you very much!


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
  •