86Stang Posted June 27, 2008 Share Posted June 27, 2008 I've got this code that I'm showing in a textarea field of a form. <?php while(current($_POST) != "-1000") { $temp = addslashes(current($_POST)); $row = mysql_fetch_assoc(mysql_query("SELECT * FROM mytable WHERE id='$temp'")); echo $row['description']; next($_POST); } ?> The problem is line spacing. As is, the code shows all records selected without any line breaks. However, if I try something like: echo $row['description'] . "\n\n"; It'll give me two lines between records (which is what I want in case that wasn't clear) but also gives me four lines before the first record. I thought I had empty records that it was reading but after double-checking I know I don't have any such animals. Any idea on what's going on? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 27, 2008 Share Posted June 27, 2008 I can only assume you have something else prior to the loop causing the problem. Any chance of you posting more of the code you're using? Quote Link to comment Share on other sites More sharing options...
86Stang Posted June 27, 2008 Author Share Posted June 27, 2008 Aye aye Cap'n!! <?php require ("config.php"); $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); mysql_select_db($db) or die ("Unable to select database!"); ?> <html> <head> <title></title> </head> <body> <form method="post" action="sendmail.php"> <table> <tr><td>Email: </td><td><input name="email" type="text"></td></tr> <tr> <td>Message: </td> <td> <textarea name="message" rows="8" cols="40" READONLY> <?php while(current($_POST) != "-1000") { $temp = addslashes(current($_POST)); $row = mysql_fetch_assoc(mysql_query("SELECT * FROM mytable WHERE id='$temp'")); echo $row['description']; next($_POST); } ?> </textarea> </td> </tr> <tr><td> </td><td><input type="submit" value="Email"></td></tr> </table> </form> </body> </html> That's the code, the whole code and nothing but the code so help me god. Quote Link to comment Share on other sites More sharing options...
86Stang Posted June 30, 2008 Author Share Posted June 30, 2008 Anyone? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 30, 2008 Share Posted June 30, 2008 Hmm...well it doesn't look like there's anything before the output from the database does it? I know you said you'd checked for empty fields, but are you 100% sure? It seems the most likely cause. Also, the above code cannot be the code with the line break issue, since there are no line breaks in that code. You should really post the exact code with the problem. Have you checked the source of the relevant bit? And finally, I really don't get what's going on with your loop. Perhaps if you explained what you're trying to do, we might be able to provide a solution to that and fix the odd line break problem in the process. Quote Link to comment Share on other sites More sharing options...
86Stang Posted June 30, 2008 Author Share Posted June 30, 2008 I double checked all records in the DB for empty records, or at least empty descriptions which is the column I'm trying to display and there are zero empty columns/fields. That's what makes my fix that I thought I'd try so bizarre. <?php while(current($_POST) != "-1000") { $temp = addslashes(current($_POST)); $row = mysql_fetch_assoc(mysql_query("SELECT * FROM mytable WHERE id='$temp'")); if ($row['description'] !="") { echo $row['description'] . "\n\n"; } next($_POST); } ?> That would tell me that it's finding empty description fields everytime but it fixed the spacing issue so I'm calling it good at this point. Thanks for your input though - it's always nice to know phpfreaks is here for those of us forced to develop in a vacuum (or at least it feels that way sometimes!). Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 30, 2008 Share Posted June 30, 2008 Glad you got it solved. But have you tried selected the empty rows and seeing what's returned? $sql = "SELECT * FROM mytable WHERE description=''"; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ print_r($row); } Quote Link to comment 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.