Page 1 of 1

Dynamic Friendly Report Format

Posted: Sat Mar 07, 2009 6:37 am
by olimess
Hi everyone,

I'm sure this is probably fairly easy but I'm not sure how to go about creating my idea and so I'm looking for someone to lead me in the right direction.

Here's the idea. I have a flash system built where by users can select certain options when building a product. Not all options need to be selected, although selecting certain options is mandatory. Once the user is done, they confirm and place their order. Flash then passes all variables (option settings etc) to a PHP page. Using PHP I check to see which options have been selected and which options haven't been selected. This is done similar to the following:

Code: Select all

 
if ($_POST['option1'] != ""){
        $txtMessage .= "<strong>Option 1 Details</strong><br />";
        $txtMessage .= "Detail 1: " . $_POST['option1detail1'] . "<br />";
        $txtMessage .= "Detail 2: " . $_POST['option1detail2'] . "<br />";
        $txtMessage .= "Detail 3: " . $_POST['option1detail3'] . "<br />";
}
 
if ($_POST['option2'] != ""){
        $txtMessage .= "<strong>Option 1 Details</strong><br />";
        $txtMessage .= "Detail 1: " . $_POST['option2detail1'] . "<br />";
        $txtMessage .= "Detail 2: " . $_POST['option2detail2'] . "<br />";
        $txtMessage .= "Detail 3: " . $_POST['option2detail3'] . "<br />";
}
 
if ($_POST['option3'] != ""){
        $txtMessage .= "<strong>Option 1 Details</strong><br />";
        $txtMessage .= "Detail 1: " . $_POST['option3detail1'] . "<br />";
        $txtMessage .= "Detail 2: " . $_POST['option3detail2'] . "<br />";
        $txtMessage .= "Detail 3: " . $_POST['option3detail3'] . "<br />";
}
 
//Mandatory Information
    $txtMessage .= "<strong>Option 4 Details</strong><br />";
    $txtMessage .= "Detail 1: " . $_POST['option4detail1'] . "<br />";
    $txtMessage .= "Detail 2: " . $_POST['option4detail2'] . "<br />";
    $txtMessage .= "Detail 3: " . $_POST['option4detail3'] . "<br />";
 

As you can see from above, I have complied all of the options into the $txtMessage variable, which can then be sent as part of an HTML email or displayed as a print out page for the user.

The problem with my approach is that each option section will appear one right after each other in the email or print out. This is very unprofessional looking and not good for the trees (too much wasted space per page requires more paper when printing).

A much better approach would be to display each selected option section dynamically in a 2 or 3 column approach. In other words, as PHP determines which sections have been selected, it will organize these sections into a row of 2 or 3 columns before beginning a new row.

Hopefully this makes sense. The result should provide me with a much cleaner and organized order report while allowing the user to use much less paper during printing.

I appreciate any suggestions. Thanks!
Olimess

Re: Dynamic Friendly Report Format

Posted: Sun Mar 08, 2009 12:56 am
by Benjamin
This is untested:

Code: Select all

 
<?php
 
define('TABLE_COLUMNS', 2);
 
$sections = array();
 
if ($_POST['option1'] != ""){
    $sections[] = "
        <strong>Option 1 Details</strong><br />
        Detail 1: {$_POST['option1detail1']}<br />
        Detail 2: {$_POST['option1detail2']}<br />
        Detail 3: {$_POST['option1detail3']}<br />
    ";
}
 
if ($_POST['option2'] != ""){
    $sections[] = "
        <strong>Option 2 Details</strong><br />
        Detail 1: {$_POST['option2detail1']}<br />
        Detail 2: {$_POST['option2detail2']}<br />
        Detail 3: {$_POST['option2detail3']}<br />
    ";
}
 
if ($_POST['option3'] != ""){
    $sections[] = "
        <strong>Option 3 Details</strong><br />
        Detail 1: {$_POST['option3detail1']}<br />
        Detail 2: {$_POST['option3detail2']}<br />
        Detail 3: {$_POST['option3detail3']}<br />
    ";
}
 
//Mandatory Information
$sections[] = "
    <strong>Option 4 Details</strong><br />
    Detail 1: {$_POST['option4detail1']}<br />
    Detail 2: {$_POST['option4detail2']}<br />
    Detail 3: {$_POST['option4detail3']}<br />
";
 
    ?>
    <table cellspacing="0">
        <?php while (count($sections) > 0) { ?>
      <tr>
      <?php for ($i = 0; $i < TABLE_COLUMNS; $i++) { ?>
        <?php if (null !== ($data = array_shift($sections))) { ?>
          <td><?php echo $data; ?></td>
        <?php } else { ?>
          <td>&nbsp;</td>
        <?php } ?>
      <?php } ?>
      </tr>
        <?php } ?>
    </table>
 

Re: Dynamic Friendly Report Format

Posted: Sun Mar 08, 2009 7:42 am
by olimess
Thanks astions!

I'll try it out and let you know how it goes.


Olimess