Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Displaying values in forms using PHP/SQL

Options
  • 16-03-2005 5:30pm
    #1
    Closed Accounts Posts: 680 ✭✭✭


    I want to displaying the entire contents of a table, in a HTML form, but i want to display them like this, where the values are displayed horizontally in groups of 3s(where "value" is the name and address of an object), so that they can be printed out on label paper. Is this possible? So far all i can do is display them vertically in a row, but i can't get them going across.

    <table width="75%" border="1" height="175">
    <tr>
    <td>
    <div align="center">Value1</div>
    </td>
    <td>
    <div align="center">Value2</div>
    </td>
    <td>
    <p align="center">Value3</p>
    </td>
    </tr>
    <tr>
    <td>
    <div align="center">Value4</div>
    </td>
    <td>
    <div align="center">Value5</div>
    </td>
    <td>
    <div align="center">Value6</div>
    </td>
    </tr>
    <tr>
    <td>
    <div align="center">Value7</div>
    </td>
    <td>
    <div align="center">Value8</div>
    </td>
    <td>
    <div align="center">Value9</div>
    </td>
    </tr>
    </table>


Comments

  • Closed Accounts Posts: 680 ✭✭✭Amaru


    Apparently you'll have to put that in a HTML page to see what i mean!


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    I think I know what you mean, and it's a pretty simple one :)

    For the sake of this example, $args[] is the array containing the values you want to output.
    [php]
    <table width="75%" border="1" height="175">
    <tr>

    <?php
    $last_col = 0;
    for($i = 0; $i < count($args); $i++) {
    print("<td><div align=\"center\">".$args[$i]."</div></td>");
    $last_col++;

    if($last_col % 3 == 0) {
    print("</tr><tr>");
    $last_col = 0;
    }
    }

    ?>
    </tr>
    </table>
    [/php]


  • Closed Accounts Posts: 680 ✭✭✭Amaru


    Yeah that looks to be exactly what i want, but one question:

    how do i put the values in an array? Do i need to put them in an array?

    Right now they're sitting in a table in a database.


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    You need to look up sql functions and how to run queries against your database, and hotw to get arrays out of these resultsets. www.php.net is your first stop.


  • Closed Accounts Posts: 680 ✭✭✭Amaru


    I think i've found the commands i need. I'll keep you posted on my progress!


  • Advertisement
  • Closed Accounts Posts: 680 ✭✭✭Amaru


    Right, i got the values fed into and array and everything is lovely! Except for one thing.

    The format of the sheets is 3 labels across, by 7 labels down. Now, the code you gave me is fine for the 3 across, but is there any way to ensure that it only ever fits 7 boxes down to a page/screen?


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    Amaru wrote:
    Right, i got the values fed into and array and everything is lovely! Except for one thing.

    The format of the sheets is 3 labels across, by 7 labels down. Now, the code you gave me is fine for the 3 across, but is there any way to ensure that it only ever fits 7 boxes down to a page/screen?

    Yep, just have something like a row counter that gets incremented at each new row, then break out of the loop when it reaches 7.


  • Closed Accounts Posts: 680 ✭✭✭Amaru


    How do you mean?

    I want it to keep printing 3 X 7's, so i assume the loop would be, similar to the rows
    $last_row++;

    if($last_row % 7 == 0) {
    print(?);
    $last_row = 0;
    }
    So what would be in the print statement where the "?" is?


Advertisement