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

Reply
 
Thread Tools Display Modes
  #11  
Old 01-09-2005, 02:13 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Change this:
PHP Code:
while ($cat $DB_site->fetch_array($categories))
{
    
$cat_cache[$cat['parentcategory']][] = $cat;

To This:

PHP Code:
while ($cat $DB_site->fetch_array($categories))
{
    
$cat_cache[$cat['parentcategory']][] = $cat;

echo 
'<pre>';
print_r($cat_cache);
echo 
'</pre>'
You'll be able to see how the array looks and works better then (only for development purposes of course
Reply With Quote
  #12  
Old 01-09-2005, 09:26 PM
Link14716's Avatar
Link14716 Link14716 is offline
 
Join Date: Jun 2002
Location: Georgia, USA
Posts: 2,519
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice job with that one Xenon.
Reply With Quote
  #13  
Old 01-09-2005, 09:43 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thx Matt
Reply With Quote
  #14  
Old 01-09-2005, 10:18 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

you know i have one i need to optimise too, but i can't figure it out, although was thinking that i'd be easier to do it via the datastore as the query in the loop takes data provided by the loop in order to return a result and it's even got a loop in the loop :-S

it's from the vBFriends hack
Reply With Quote
  #15  
Old 01-10-2005, 01:29 AM
cinq's Avatar
cinq cinq is offline
 
Join Date: Oct 2002
Posts: 1,398
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dean C
..
You'll be able to see how the array looks and works better then (only for development purposes of course
Thanks Dean, made it much easier for me to visualize
Reply With Quote
  #16  
Old 01-10-2005, 03:39 AM
cinq's Avatar
cinq cinq is offline
 
Join Date: Oct 2002
Posts: 1,398
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok using similar code, I am trying to show a list of authors, and their respective written articles.

This is the code i am trying to use :

PHP Code:
$authorquery $DB_site->query("
        SELECT * FROM " 
TABLE_PREFIX "articles_article a
        LEFT JOIN " 
TABLE_PREFIX "user u
        ON a.author=u.username
        ORDER BY a.author asc
        "
);

$artbyauthorquery $DB_site->query("
        SELECT articles_articleid, title, author
        FROM " 
TABLE_PREFIX "articles_article
        ORDER BY publishdate desc
        "
);

$author_cache = array();
while (
$author $DB_site->fetch_array($artbyauthorquery))
{
    
$author_cache[$author['author']][] = $author;
}

// authors
foreach ($author_cache['author'] AS $author)
{
           
$userid $author["userid"];
        
$author $author["author"];

        
// articles by the authors
        
foreach ($author_cache[$author] AS $article)
        {
            
$arttitle=$article["title"];
            
$artid=$article["articles_articleid"];
            eval(
'$authorartbit .= "' fetch_template('vbArticles_authorartbit') . '";');
        }
     eval(
'$authorbit .= "' fetch_template('vbArticles_authorbit') . '";');
}

    
$navbits construct_navbits(array('' => $vbphrase['vbarticles']));
    eval(
'$navbar = "' fetch_template('navbar') . '";');
    eval(
'print_output("' fetch_template('vbArticles_authorlist') . '");');

However it gives me an error at the line :
PHP Code:
foreach ($author_cache['author'] AS $author
Something to do with the 'author' there I think. I need to put in the value there which is the name of the authors, correct ?

foreach works with strings in the array too, so how come this is not accepted ?
error is "Invalid argument supplied for foreach()".
Reply With Quote
  #17  
Old 01-10-2005, 08:30 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm didn't analyze the script, but at first glance it looks like
PHP Code:
$author_cache['author'
is not filled like that.

PHP Code:
$author_cache[$author['author']][] = $author
Fills it like "array['name of author']" and not with the rowname 'author'
Reply With Quote
  #18  
Old 01-10-2005, 10:10 AM
cinq's Avatar
cinq cinq is offline
 
Join Date: Oct 2002
Posts: 1,398
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Marco, but nope, I don't think that would work either.
Because, the $author['author'] is the result of the query on articles by authors, not the authors query.
Reply With Quote
  #19  
Old 01-10-2005, 10:18 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes i know, maybe i am wrong.
PHP Code:
while ($author $DB_site->fetch_array($artbyauthorquery)) 

    
$author_cache[$author['author']][] = $author

Would give something like the following (assuming some about the author table now):
$author_cache['jim'][0] = array('jim','doe','UK',3,......)
$author_cache['john'][0] = array('john','smith','germany',4,......)

now you ask for the entry "$author_cache['author']" unless there is an author named 'author', this would give no results.

Maybe i am looking complete wrong now, but just shoot me i am wearing a bullet proof vest
Reply With Quote
  #20  
Old 01-10-2005, 10:22 AM
cinq's Avatar
cinq cinq is offline
 
Join Date: Oct 2002
Posts: 1,398
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yep you're right. You got me thinking ..
I am trying to find a way about it.

If i were to perform another :

PHP Code:
while ($authorsname $DB_site->fetch_array($authorquery))
{
    
$authorname_cache[] = $authorsname ;

This would give me an array of the author's names in $authorname_cache[].
How could I use this in the foreach statement, any idea ?
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 04:45 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.04089 seconds
  • Memory Usage 2,279KB
  • 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
  • (8)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)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