Hi Everyone,

I have a form that users fill out, which is then processed by a different script and echoed on another page.

The form has an a series of text areas where the user can enter information

ex.
1: Line 1
2:
Line 2

3"
_____
4:
Line 4
___

and is echoes as

Line 1
Line 2

Line 4

but if no information is input on one (or more) of the lines, I want it to echo as

Line 1
Line 2
Line 4

Is this possible?

Thanks for the input

    something like:

    if(!empty($_POST[line_1])) echo $_POST[line_1].'<br>';
    if(!empty($_POST[line_2])) echo $_POST[line_2].'<br>';
    if(!empty($_POST[line_3])) echo $_POST[line_3].'<br>';
    if(!empty($_POST[line_4])) echo $_POST[line_4].'<br>';
    

      Or, if you used an array of elements in the form, e.g.

      1: <input type="text" name="data[]"><br>
      2: <input type="text" name="data[]"><br>
      3: <input type="text" name="data[]"><br>
      <!-- etc. -->

      then you could do something like:

      $data = array_filter($_POST['data']);
      echo implode("<br>", $data);

        Thanks for the replies.

        I forgot to mention that the form gets input to a db, and then pulled from the db and echoed onto a page.

        So I don't think the $_post method would work in this situation, but I could be wrong.

        Thanks

          once submitted you don't have to put it in to the db then pull it out if its one operation. if its multiple operations just adjust what variable you are processing. what have you tried so far? posting some actual code will help us help you.

            So here's what I have
            warning it's not pretty at alli'm just a php puppy
            I'm not concerned right now with how the code looks, as much as I am with getting this thing to function. If a cleaner code makes it function, I'm all for it though.

            So a person would input here in a text area here:

            	<?php
            $id ='110'; //Out/COS/Class 1
            $results = mysql_query("SELECT up1 FROM $tbl_name WHERE id='$id'");
            $values = mysql_fetch_array($results);
            ?>
            <input type="text" name="out1" size="45" maxlength="100" value="<?php echo $values['up1']; ?>"/><input type="hidden" name="textid" value="<?php echo $id; ?>" /><br />
            
            <?php
            $id ='110'; //Out/COS/Class 2
            $results = mysql_query("SELECT up2 FROM $tbl_name WHERE id='$id'");
            $values = mysql_fetch_array($results);
            ?>
            <input type="text" name="out2" size="45" maxlength="100" value="<?php echo $values['up2']; ?>"/><input type="hidden" name="textid" value="<?php echo $id; ?>" /><br />
            
            <?php
            $id ='110'; //Out/COS/Class 3
            $results = mysql_query("SELECT up3 FROM $tbl_name WHERE id='$id'");
            $values = mysql_fetch_array($results);
            ?>
            <input type="text" name="out3" size="45" maxlength="100" value="<?php echo $values['up3']; ?>"/><input type="hidden" name="textid" value="<?php echo $id; ?>" /><br />
            

            It would get processed by this script:

            $query="UPDATE $tbl_name SET up1='$out1' WHERE id='110'";
            $result=mysql_query($query);
            $query="UPDATE $tbl_name SET up2='$out2' WHERE id='110'";
            $result=mysql_query($query);
            $query="UPDATE $tbl_name SET up3='$out3' WHERE id='110'";
            $result=mysql_query($query);
            

            and be echoed on a different page. I have tried multiple things, including:

            <?php
            $query="SELECT * FROM $tbl_name WHERE id ='110'";
            $result=mysql_query($query);
            while ($row = mysql_fetch_array($result))
            {
            $array = array('<h5>', ($row['up1']),($row['up2']),($row['up3']), '</h5>');
            echo implode("\n", $array);
            } 
            mysql_free_result($result);
            ?>
            

            and 1 statement for multiple rows (different page, so different code, but same premise):

            <?php
            $s = array(33,34,35,36);
            $values = implode("', '", $s);
            $query="SELECT * FROM $tbl_name WHERE id IN ('$values')";
            $result=mysql_query($query);
            while ($row = mysql_fetch_array($result))
            {
            echo '<h5>', ($row['rem1']), '</h5>';
            }
            mysql_free_result($result);
            ?><br />
            

            I've tried all kinds variations with <br> and /n as well. I can make the plain old implode work, but I am wondering if it's possible to make it work vertically (like a list).

            Thanks again for all the help.

              i don't understand what you mean by implode vertically.

              this should work if i understand the issue:

              while ($row = mysql_fetch_array($result))
              {
              if(!empty($row['rem1'])) echo '<h5>', ($row['rem1']), '</h5>';
              }
              mysql_free_result($result);
              

                I apologize if I'm not making myself clear. I'm really new to PHP.

                The times I've imploded something

                <?php
                $query="SELECT * FROM $tbl_name WHERE id ='10'";
                $result=mysql_query($query);
                while ($row = mysql_fetch_array($result))
                {
                $array = array('<h5>', ($row['p1']), '</h5>', '<h5>', ($row['act']), '</h5>', '<h5>', ($row['p2']), '</h5>', '<h5 class="update1">', ($row['up1']), '</h5>', '<h5 class="update2">', ($row['up2']), '</h5>', '<h5 class="update3">', ($row['up3']), '</h5>', '<h5 class="update4">', ($row['up4']), '</h5>', '<h5 class="update5">', ($row['up5']), '</h5>', '<h5 class="update6">', ($row['up6']), '</h5>', '<h5 class="update7">', ($row['up7']), '</h5>', '<h5 class="update8">', ($row['up8']), '</h5>', '<h5 class="update9">', ($row['up9']), '</h5>', '<h5 class="update10">', ($row['up10']), '</h5>');
                $comma_separated = implode(" ", $array);
                echo $comma_separated;
                } 
                mysql_free_result($result);
                ?>
                

                What echoes is a horizontal line of print.

                p1 act p2 extra up1 up2 ...

                What I am looking to do now, is have it print vertically, like a column as opposed to a row:

                p1
                act
                p2
                extra
                up1
                up2
                ...

                And in the process, implode the line, so if there is any blank cells in my db table, the next row with information in it would proceed the previous row with information, and there wouldn't be a blank space (empty line) between the two.

                Thank you for all your guidance. I appreciate it.

                  <?php
                  $query="SELECT * FROM $tbl_name WHERE id ='10'";
                  $result=mysql_query($query);
                  while ($row = mysql_fetch_array($result))
                  {
                  if(!empty($row['p1'])) echo '<h5>'.$row['p1'].'<h5>';
                  } 
                  mysql_free_result($result);
                  ?>
                  

                  do that for each line

                    Thank you Dagon. But unfortunately, that echoes it all on one line.

                    I tried (where there are values for 33, 34, and 36 only)

                    <?php
                    $query="SELECT * FROM $tbl_name WHERE id ='33'";
                    $result=mysql_query($query);
                    while ($row = mysql_fetch_array($result))
                    {
                    if(!empty($row['p1'])) echo '<h5>'.$row['rem1'].'<h5>';
                    }
                    mysql_free_result($result);
                    ?>
                    <?php
                    $query="SELECT * FROM $tbl_name WHERE id ='34'";
                    $result=mysql_query($query);
                    while ($row = mysql_fetch_array($result))
                    {
                    if(!empty($row['p1'])) echo '<h5>'.$row['rem1'].'<h5>';
                    }
                    mysql_free_result($result);
                    ?>
                    <?php
                    $query="SELECT * FROM $tbl_name WHERE id ='35'";
                    $result=mysql_query($query);
                    while ($row = mysql_fetch_array($result))
                    {
                    if(!empty($row['p1'])) echo '<h5>'.$row['rem1'].'<h5>';
                    }
                    mysql_free_result($result);
                    ?>
                    <?php
                    $query="SELECT * FROM $tbl_name WHERE id ='36'";
                    $result=mysql_query($query);
                    while ($row = mysql_fetch_array($result))
                    {
                    if(!empty($row['p1'])) echo '<h5>'.$row['rem1'].'<h5>';
                    }
                    mysql_free_result($result);
                    ?>
                    

                    And was echoed as:
                    33 34 36 (the actual values from the db, not the numbers)

                    I'm looking for it to echo as:
                    33
                    34
                    36
                    (the actual values from the db, not the numbers)

                    I'll keep playing with this. Thank you very much.

                      h5 is a block level element so there should be a line break after it, what's you outputted html look like? you are viewing it with a web browser?

                        The outputted html is showing the values on one horizontal line. Where there is an empty value, it is not showing - so that works. But it still looks like this:

                        33 34 36

                        as opposed to the desired

                        33
                        34
                        36

                        Thanks

                          view source, this is an html\css issue not a php one

                            a link to the appropriate web page would be helpful.

                              Would you mind explaining how it would be an html/css issue?

                              Unfortunately, the site is on an intranet, and only people within our business walls can see it (without a VPN).

                              thank you

                                as h5 is a block level element there would normally be a line break after it, unless its been defined as inline

                                  it has been defined as inline

                                    bingo, so use something else

                                      Dagon,

                                      YOU ARE A LIFESAVER AND GENIUS!

                                      This is exactly what I was looking for. Thank you so much.

                                        Write a Reply...