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

Reply
 
Thread Tools Display Modes
  #1  
Old 11-20-2009, 07:12 PM
Mythotical Mythotical is offline
 
Join Date: Jun 2004
Location: Booneville, AR, USA
Posts: 1,428
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Row count

Did anything change how row count is done?

PHP Code:
$sql $vbulletin->db->query_read("SELECT * FROM `" TABLE_PREFIX "download_cats` WHERE cat_active = '1'");

$total $vbulletin->db->num_rows($sql);
$i=0;
$perrow $total-2;

while (
$row $db->fetch_array($sql))
{
        
$i++;

    if (
$total !== 0)
    {
  
    if (
$total $perrow){
        
$catc '</td>';
        
$perrow $perrow+2;
    } else {
        
$perrow $perrow-2;
        
$catc '</td></tr><tr>';
    } 
I'm not sure if that is the problem but when I refresh my page is keeps displaying:
HTML Code:
</td></td></tr><tr>
Not sure if its the row count or not. Hard to say right now.

Thanks
Steve
Reply With Quote
  #2  
Old 11-20-2009, 08:00 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

num_rows is still num_rows. You are missing an end } to your code though.
Reply With Quote
  #3  
Old 11-20-2009, 08:12 PM
Mythotical Mythotical is offline
 
Join Date: Jun 2004
Location: Booneville, AR, USA
Posts: 1,428
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nah its there, here is the full snippet:
PHP Code:
$sql $vbulletin->db->query_read("SELECT * FROM `" TABLE_PREFIX "download_cats` WHERE cat_active = '1'");

$total $vbulletin->db->num_rows($sql);
$i=0;
$perrow $total-2;

while (
$row $db->fetch_array($sql))
{
    
$cid $row['catid'];
    
$cat $row['catitle'];
    
$description $row['cat_description']; 
    
$caticon $row['cat_icon'];
        
$i++;

    if (
$total !== 0)
    {
  
    if (
$total $perrow){
        
$catc '</td>';
        
$perrow $perrow+2;
    } else {
        
$perrow $perrow-2;
        
$catc '</td></tr><tr>';
    }

            
$cat_data vB_Template::create('bfc_download_cat_bit');
            
$cat_data->register('cid'$cid);
            
$cat_data->register('cat'$cat);
            
$cat_data->register('description'$description);
            
$cat_data->register('caticon'$caticon);
            
$cat_data->register('catc'$catc);
            
$cat_data->register('cat_bit'$cat_bit);
            
$cat_bit .= $cat_data->render();  
    }


Reply With Quote
  #4  
Old 11-20-2009, 08:42 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you are just getting "</td></td></tr><tr>" all the time, then perhaps your template is incorrect. I assume you want something else to be input in there which is missing?
Reply With Quote
  #5  
Old 11-20-2009, 08:57 PM
Mythotical Mythotical is offline
 
Join Date: Jun 2004
Location: Booneville, AR, USA
Posts: 1,428
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you look at the code I have it set that if there are 2 cats to display then it will and it will add </td></tr><tr> then start a new row but if their is only one it will not throw that out yet, it will use </td> only instead.
Reply With Quote
  #6  
Old 11-20-2009, 09:06 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, I get that. perhaps for debugging purposes, you should be spitting $perrow out also to see what it is set to.
Reply With Quote
  #7  
Old 11-20-2009, 09:11 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just a suggestion:
Put each cell into an array, and then use array_chunk to get your groups. Much more solid than messing around with counters and stuff.
Reply With Quote
  #8  
Old 11-20-2009, 10:38 PM
Mythotical Mythotical is offline
 
Join Date: Jun 2004
Location: Booneville, AR, USA
Posts: 1,428
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by SirAdrian View Post
Just a suggestion:
Put each cell into an array, and then use array_chunk to get your groups. Much more solid than messing around with counters and stuff.
Um....how do you mean? Got an example or somewhere I can look at an example? I'm a visual person, visual aids help me more to do code than just being told.

Cheers
Steve
Reply With Quote
  #9  
Old 11-20-2009, 10:52 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here's a sample
PHP Code:
$columns 5;
$width   floor(100 $columns);

// generate $cells array containing each HTML cell
$cells = array();
while (
$row $db->fetch_array($result)) {
    
$cells[] = '<td style="width: ' $width '%">HTML For the Cell</td>';
}

// pad with empty cells until last row would be full
while (count($prepared) % $columns) {
    
$prepared[] = '<td style="width: ' $width '%"></td>';
}

// group into rows with variable number of columns
$rows '';
foreach (
array_chunk($prepared$columns) as $row) {
    
$rows .= '<tr>' implode(' '$row) . '</tr>';
}

// done
return '<table border="0" width="100%">' $rows '</table>'
Reply With Quote
  #10  
Old 11-20-2009, 11:02 PM
Mythotical Mythotical is offline
 
Join Date: Jun 2004
Location: Booneville, AR, USA
Posts: 1,428
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by SirAdrian View Post
Here's a sample
PHP Code:
$columns 5;
$width   floor(100 $columns);

// generate $cells array containing each HTML cell
$cells = array();
while (
$row $db->fetch_array($result)) {
    
$cells[] = '<td style="width: ' $width '%">HTML For the Cell</td>';
}

// pad with empty cells until last row would be full
while (count($prepared) % $columns) {
    
$prepared[] = '<td style="width: ' $width '%"></td>';
}

// group into rows with variable number of columns
$rows '';
foreach (
array_chunk($prepared$columns) as $row) {
    
$rows .= '<tr>' implode(' '$row) . '</tr>';
}

// done
return '<table border="0" width="100%">' $rows '</table>'
Ahhhhh, I see what you mean now, thank you very much. Never fails you come to my rescue on things. LOL

I'll have to give it a try tomorrow, heading out for a night on the town with the wife.

--------------- Added [DATE]1258848871[/DATE] at [TIME]1258848871[/TIME] ---------------

BTW, I figured out that I was using wrong code in the template:
HTML Code:
{vb:var catc}
But once I changed to:
HTML Code:
{vb:raw catc}
It all worked out, the code appearing at top went away so now I just need to convert to Adrian's suggestion and it will be good to go.
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 05:40 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.05848 seconds
  • Memory Usage 2,291KB
  • 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
  • (3)bbcode_html
  • (4)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete