vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   line breaks (https://vborg.vbsupport.ru/showthread.php?t=64446)

sabret00the 04-27-2004 03:46 PM

line breaks
 
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?

PHP Code:

         $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

PHP Code:

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

or something else?

[high]* sabret00the thinks he might have to dig out his php book :nervous:[/high]

Xenon 04-27-2004 04:14 PM

nope, not around the query.

lets say

you have this:
PHP Code:

$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

PHP Code:

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

PHP Code:

            $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 :)

PHP Code:

$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

[high]* sabret00the is too tired for this now :([/high]

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?


All times are GMT. The time now is 07:38 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01253 seconds
  • Memory Usage 1,764KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (14)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete