Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 04-27-2004, 03:46 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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()."'"); 
Reply With Quote
  #2  
Old 04-27-2004, 03:47 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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())
Reply With Quote
  #3  
Old 04-27-2004, 03:58 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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]
Reply With Quote
  #4  
Old 04-27-2004, 04:14 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #5  
Old 04-27-2004, 04:42 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #6  
Old 04-27-2004, 05:08 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

just put a $text = nl2br($text); before the evel project bits part
Reply With Quote
  #7  
Old 04-27-2004, 05:14 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks xenon you're a great help
Reply With Quote
  #8  
Old 04-27-2004, 06:00 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default



you're always welcome
Reply With Quote
  #9  
Old 04-27-2004, 07:03 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

sorry to be a pain xenon but it didn't work
Reply With Quote
  #10  
Old 04-27-2004, 07:22 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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") . '";');
    } 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:00 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.04810 seconds
  • Memory Usage 2,269KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete