vb.org Archive

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

Kirk Y 05-28-2006 11:53 PM

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?

Hellcat 05-29-2006 12:12 AM

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.

Kirk Y 05-29-2006 12:20 AM

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"); 


Adrian Schneider 05-29-2006 01:13 AM

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.

Kirk Y 05-29-2006 01:24 AM

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


All times are GMT. The time now is 11:50 PM.

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.01119 seconds
  • Memory Usage 1,729KB
  • 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
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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