vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   MySQL Count Rows (https://vborg.vbsupport.ru/showthread.php?t=175692)

PaulSonny 04-10-2008 02:05 AM

MySQL Count Rows
 
Hello Everybody,

I think i'm looking around the right area but struggling and would really appreciate any help.

Basically, I'm want to count how many 'rows' I have in my DB table and then display that figure in the AdminCP like Total: $totalrows.

I also want to be able to put a SQL constraint in, for example count how many 'rows' for id=0.

Any help?

Thanks, Paul.

Eikinskjaldi 04-10-2008 03:42 AM

Just use the mysql count function.

select count(*) from table

or

select count(*) from table where foo=bar

PaulSonny 04-10-2008 08:22 AM

This seems like a really noob error but I cant get it working.

I have this SQL statement:
Quote:

$counttotalproduct = $vbulletin->db->query_read("SELECT COUNT(*) FROM " . TABLE_PREFIX . "cart_product");
then I have this line to show the result?

Total Products: $counttotalproduct

But its showing up as:

Total Products: Resource id #17

Any help?

Thanks, Paul.

Dismounted 04-10-2008 09:49 AM

You need to loop the results to find the value, alternatively, do this instead:
PHP Code:

$counttotalproduct $vbulletin->db->query_first("SELECT COUNT(*) AS countrows FROM " TABLE_PREFIX "cart_product");
$counttotalproduct $counttotalproduct['countrows']; 


PaulSonny 04-10-2008 10:02 AM

Quote:

Originally Posted by Dismounted (Post 1487358)
You need to loop the results to find the value, alternatively, do this instead:
PHP Code:

$counttotalproduct $vbulletin->db->query_first("SELECT COUNT(*) AS countrows FROM " TABLE_PREFIX "cart_product");
$counttotalproduct $counttotalproduct['countrows']; 


Worked an absolute treat, thanks all for help :)

Thanks, Paul.


All times are GMT. The time now is 09:42 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.02213 seconds
  • Memory Usage 1,723KB
  • 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
  • (2)bbcode_php_printable
  • (2)bbcode_quote_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