Jump to content

[SOLVED] Any idea why I'd be getting line breaks before the records?


86Stang

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.