Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Displaying values in forms using PHP/SQL

  • 16-03-2005 05: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, Registered Users 2 Posts: 68,173 ✭✭✭✭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, Registered Users 2 Posts: 68,173 ✭✭✭✭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, Registered Users 2 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