Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-28-2006, 11:53 PM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Array Issues

I've made a really simple shoutbox, so that administrators on my forum can put up important messages for all the members to see, just in case they don't browse the forums. This is the code I'm using to pull the posts from my database:

PHP Code:
$blast $db->query_first("SELECT * FROM blastmsg ORDER BY blastid DESC"); 
Then I use $blast[message] to post the message. The problem is that it's only posting the newest message -- I want it to post all of the messages, or at the very least 3. How should I go about doing this?
Reply With Quote
  #2  
Old 05-29-2006, 12:12 AM
Hellcat Hellcat is offline
 
Join Date: May 2003
Location: Germany
Posts: 560
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Use query_read() instead of query_first() and alter the SQL statement to get all "shouts" you want (like the last 3 or whatever).

Then loop through the result with fetch_array() to get the returned rows and post the messages one by one.
Reply With Quote
  #3  
Old 05-29-2006, 12:20 AM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$blast_msg $db->query_read("SELECT * FROM blastmsg ORDER BY blastid DESC");

        if (!
$db->num_rows($blast_msg))
    {
        
$blasterr "<div align=center><i>There are no blast messages!</i></div>";
    }
    else
    {
    while (
$blast $db->fetch_array($blast_msg))
         {
        
$user $blast[user];
                
$date $blast[date];
                
$message $blast[message];
         }
    } 
I tried this also -- is this what you're talking about? Either way, this one didn't work either.

Should I try this instead:
PHP Code:
$blast_msg $db->query_read("SELECT * FROM blastmsg ORDER BY blastid DESC LIMIT 0,3"); 
Reply With Quote
  #4  
Old 05-29-2006, 01:13 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try something like this:
PHP Code:
$blast_msg $db->query_read("
    SELECT *
    FROM blastmsg
    ORDER BY blastid DESC
    LIMIT 3
"
);

if (!
$db->num_rows($blast_msg))
{
    
$blasterr '<div align="center"><em>There are no blast messages!</em></div>';
}
else
{
    while (
$blast $db->fetch_array($blast_msg))
    {
        
$user $blast['user'];
        
$date $blast['date'];
        
$message $blast['message'];
        
        
// Here is where you display the current message (ex)...
        
$blasterr .= "<div>[$date$user$message</div>";
    }

I really only added the single quotes for string array keys, and adding to the $blasterr variable with each loop. The way you have it now $user, $date and $message will just be whatever they were last, you want to display (or add to a variable) every time so they are unique.
Reply With Quote
  #5  
Old 05-29-2006, 01:24 AM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks SirAdrian -- all working fine, it's much appreciated.
Reply With Quote
Reply


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:42 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04217 seconds
  • Memory Usage 2,209KB
  • Queries Executed 11 (?)
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
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete