PDA

View Full Version : line breaks


sabret00the
04-27-2004, 03:46 PM
how do i make sure that when inserting this code into the database it adds any line breaks that may be typed out by the users?


$DB_site->query("INSERT INTO project SET
text = '".addslashes($message)."',
timestamp = '".time()."'");

Xenon
04-27-2004, 03:47 PM
well, it automatically adds linebreaks by the users into the DB.

just when you output the msg, you have to make sure they are parsed (nl2br())

sabret00the
04-27-2004, 03:58 PM
oh ok, so it's on the output side i have to worry about the line breaks, ok then, would i put the (nl2br()) around the query to select the date from the database ala

(nl2br($project = $DB_site->query("SELECT projectid, text, timestamp FROM project $clause ORDER BY projectid DESC $limit")));


or something else?

* sabret00the thinks he might have to dig out his php book :nervous:

Xenon
04-27-2004, 04:14 PM
nope, not around the query.

lets say

you have this:
$field =$DB_site->query_first("SELECT projectid, text, timestamp FROM project $clause ORDER BY projectid DESC $limit")));
echo $field['text'];

then it would show up all in one line.
but if you use

echo nl2br($field['text']);

then the linebreaks will be visible.

btw. if you use parse_bbcode it will automatically use nl2br :)

sabret00the
04-27-2004, 04:42 PM
sorry to be a pain stefan, but i don't think i'm getting this, so heres the code that outputs what i'm trying to show up with line breaks

$projects = $DB_site->query_first("SELECT projectid, text, timestamp FROM projects $clause ORDER BY projectid DESC $limit");
$projects = nl2br($projects['text']);

if (!$DB_site->num_rows($projects)) {
eval("\$projects_bits = \"".fetch_template("projects_error",1,0)."\";");
} else {
while ($project_info = $DB_site->fetch_array($projects)) {
extract($project_info);

$totalconf = number_format($DB_site->num_rows($projects));
$time_posted = vbdate('n-j-y, g:i:s a', $timestamp);

if ($bbuserinfo[usergroupid] == 6) {
eval("\$adminoptions = \"".fetch_template("projects_adminoptions",1,0)."\";");
}
eval("\$projects_bits .= \"".fetch_template("projects_bit")."\";");
}

it's all called in the templates via a simple $text inside the $projects_bit template

Xenon
04-27-2004, 05:08 PM
just put a $text = nl2br($text); before the evel project bits part :)

sabret00the
04-27-2004, 05:14 PM
thanks xenon you're a great help :D

Xenon
04-27-2004, 06:00 PM
:)

you're always welcome :)

sabret00the
04-27-2004, 07:03 PM
sorry to be a pain xenon but it didn't work :(

Xenon
04-27-2004, 07:22 PM
i suggest to use this code, that should work :)

$projects = $DB_site->query("
SELECT projectid, text, timestamp
FROM projects
$clause
ORDER BY projectid DESC
$limit
");

if (!$DB_site->num_rows($projects))
{
eval('$projects_bits = "' . fetch_template("projects_error") . '";');
}
else
{
$totalconf = number_format($DB_site->num_rows($projects));
while ($project_info = $DB_site->fetch_array($projects))
{
$project_info['text'] = nl2br($project_info['text']);
extract($project_info);
$time_posted = vbdate('n-j-y, g:i:s a', $timestamp);

if ($bbuserinfo['usergroupid'] == 6)
{
eval('$adminoptions = "' . fetch_template("projects_adminoptions") . '";');
}
eval('$projects_bits .= "' . fetch_template("projects_bit") . '";');
}

sabret00the
04-27-2004, 09:19 PM
thanks xenon, i'll give it a go in the morning :D

* sabret00the is too tired for this now :(

sabret00the
04-28-2004, 10:09 AM
i gave it a go and it worked perfectly, i'm so very grateful :)

Xenon
04-28-2004, 02:26 PM
:)

glad to hear :)

SVTBlackLight01
08-29-2004, 04:50 PM
Any idea how to apply this to custom profile fields?