jaydeesmalls Posted July 21, 2008 Share Posted July 21, 2008 Hi everybody, On one of my pages, I have a form that a user can input data into a series of lines: ex: 1:__line 1__________ 2:__line 2__________ 3:____________ 4:__line 4__________ and when the form is submitted, it is echoed in the same fashion ex. line 1 line 2 line 4 I am wondering if there is a way to make it so that if a person didn't input anything in one of the lines, the following line would be echoed up a line (sort of like implode, but vertically)? ex. line 1 line 2 line 4 Thanks for the input Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/ Share on other sites More sharing options...
wildteen88 Posted July 21, 2008 Share Posted July 21, 2008 Post your current code. Where does the user enter the *lines*? within a textarea? Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-595761 Share on other sites More sharing options...
jaydeesmalls Posted July 21, 2008 Author Share Posted July 21, 2008 Yes, within a textarea. I'm at work now, and do not have access to the code. sorry. Basically, the user fills out a form, the info is then processed by another file, and echoed on a third page. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-595818 Share on other sites More sharing options...
DarkWater Posted July 21, 2008 Share Posted July 21, 2008 Uhh...implode() has nothing to do with whether or not it ends up horizontal or vertically...that depends on what you actually implode...Did you try: echo implode("<br />", $list); >_> Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-595819 Share on other sites More sharing options...
Jabop Posted July 21, 2008 Share Posted July 21, 2008 I am assuming it'd be something like $string = explode("\n", $var) Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-595821 Share on other sites More sharing options...
DarkWater Posted July 21, 2008 Share Posted July 21, 2008 Nah, you'd need to put an HTML line break. My code was supposed to read: echo implode('<br />', $list); Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-595829 Share on other sites More sharing options...
Jabop Posted July 21, 2008 Share Posted July 21, 2008 Nah, you'd need to put an HTML line break. My code was supposed to read: echo implode('<br />', $list); Ah yes, I was thinking the lines of a text file, not the lines of a text BOX. Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-595835 Share on other sites More sharing options...
craygo Posted July 21, 2008 Share Posted July 21, 2008 If you want to remove more that one line you have to look for multiple line breaks then replace with one <?php $text = $_POST['tarea']; $array = array("\r\n\r\n", "\n\n", "\r\r"); $replace = "\r\n"; $newtext = str_replace($array, $replace, $text); echo nl2br($newtext); ?> Ray Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-595842 Share on other sites More sharing options...
DarkWater Posted July 21, 2008 Share Posted July 21, 2008 Nah, you'd need to put an HTML line break. My code was supposed to read: echo implode('<br />', $list); Ah yes, I was thinking the lines of a text file, not the lines of a text BOX. I didn't think that he was putting it back into a textbox. I think he's echoing it straight out. Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-595854 Share on other sites More sharing options...
jaydeesmalls Posted July 21, 2008 Author Share Posted July 21, 2008 Thanks for all the input. Yes, I'm echoing straight out. I'll try those both when I have the opportunity tonight. they make sense, I'm certain one of them will work. thanks again Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-595889 Share on other sites More sharing options...
jaydeesmalls Posted July 21, 2008 Author Share Posted July 21, 2008 Based on memory, I think my code looks similar to this (warning, it's not pretty at all) <?php $query="SELECT * FROM $tbl_name WHERE id='33'"; $result=mysql_query($query); while ($row = mysql_fetch_array($result)) { echo '<h5>', ($row['rem1']), '</h5>'; } mysql_free_result($result); ?><br /> <?php $query="SELECT * FROM $tbl_name WHERE id='34"; $result=mysql_query($query); while ($row = mysql_fetch_array($result)) { echo '<h5>', ($row['rem1']), '</h5>'; } mysql_free_result($result); ?><br /> <?php $query="SELECT * FROM $tbl_name WHERE id='35'"; $result=mysql_query($query); while ($row = mysql_fetch_array($result)) { echo '<h5>', ($row['rem1']), '</h5>'; } mysql_free_result($result); ?><br /> <?php $query="SELECT * FROM $tbl_name WHERE id='36'"; $result=mysql_query($query); while ($row = mysql_fetch_array($result)) { echo '<h5>', ($row['rem1']), '</h5>'; } mysql_free_result($result); ?><br /> What I'm looking for is if someone entered values in 33, 34, and 36, but not 35, it would be echo as: 33 34 36 not 33 34 36 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-595906 Share on other sites More sharing options...
jaydeesmalls Posted July 21, 2008 Author Share Posted July 21, 2008 So I tried the implode('<br />', $list); method and that created more spaces between the lines. ex. 33 34 36 ??????? Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-595963 Share on other sites More sharing options...
jaydeesmalls Posted July 22, 2008 Author Share Posted July 22, 2008 bump for the night time peeps any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-596158 Share on other sites More sharing options...
craygo Posted July 22, 2008 Share Posted July 22, 2008 problem is you are using a bunch of queries then putting a break in. Why not use 1 query. <?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 /> Ray Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-596503 Share on other sites More sharing options...
jaydeesmalls Posted July 23, 2008 Author Share Posted July 23, 2008 Craygo, so I tried what you posted, and everything gets echoed on one line. ex: 33 34 36 Thank you for the input Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-597027 Share on other sites More sharing options...
craygo Posted July 23, 2008 Share Posted July 23, 2008 my bad I forgot <h> tags don't start a new line. <?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><br />'; } mysql_free_result($result); ?> Ray Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-597499 Share on other sites More sharing options...
jaydeesmalls Posted July 23, 2008 Author Share Posted July 23, 2008 Ray, thanks again. I tried that and I am still getting blank lines between lines with information ex (if lines 34 and 35 were empty): 33 36 when I am looking for a way so it would echo: 33 36 thanks. Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-597644 Share on other sites More sharing options...
wildteen88 Posted July 23, 2008 Share Posted July 23, 2008 BY default header tags (<h1> to <h6>) have a default padding/margin. Because of this your numbers will be spaced apart. To remove padding/margin apply the following CSS h5 { padding: 0; margin: 0; } Or don't use a header tag to display your numbers. Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-597700 Share on other sites More sharing options...
jaydeesmalls Posted July 23, 2008 Author Share Posted July 23, 2008 Thanks Wildteen. I don't think I was clear on my previous post. I apologize for that. When I echo, I am looking to make it similar to how I go this implode statement to work: $query="SELECT * FROM $tbl_name WHERE id ='10'"; $result=mysql_query($query); while ($row = mysql_fetch_array($result)) { $array = array('<h5 class="update1">', ($row['up1']), '</h5>', '<h5 class="update2">', ($row['up2']), '</h5>', '<h5 class="update3">', ($row['up3']), '</h5>'); $comma_separated = implode(" ", $array); echo $comma_separated; } mysql_free_result($result); ?> In that example, it was echoed on one line, and if there was nothing input in $row['up2'], it would be replaced with a " " and the proceeding input (up3) would be echoed immediately after the initial input (up1). I am looking for a way so that instead of this happening on one horizontal line, it happens with one input per line. Thank you for helping. Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-597972 Share on other sites More sharing options...
wildteen88 Posted July 23, 2008 Share Posted July 23, 2008 Does each row have three columns, called upX (X being a number 1 to 3) If so do $query = "SELECT * FROM $tbl_name WHERE id ='10'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $i = 1; foreach($row as $item) { if(!empty($item)) { echo '<h5 class="update' . $i .'">' . $item . '</h5>'; } $i++; } } mysql_free_result($result); Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-598034 Share on other sites More sharing options...
jaydeesmalls Posted July 24, 2008 Author Share Posted July 24, 2008 Thank you Wildteen and Craygo for all your patience and assistance. I found out that it was a css issue (display:inline), and the problem is solved. I appreciate all the input. Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-598194 Share on other sites More sharing options...
unkwntech Posted July 24, 2008 Share Posted July 24, 2008 Edit: Sorry im a moron. Quote Link to comment https://forums.phpfreaks.com/topic/115874-solved-is-there-anything-like-implode-but-vertically/#findComment-598349 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.