vb.org Archive

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

teksigns 04-16-2004 03:45 AM

php mysql help ?
 
i have a table called

color_guide

it has several fields in it ....

one of them is

name

what php mysql statement would i need to use to retrieve
the "name" that has the most rows along with how many it has.....

example :

if john posted the most with 28 post i want to be able to print

John : 28

since hes the top poster......

help !

teksigns 04-16-2004 03:23 PM

Quote:

Originally Posted by my username
Use PHP's built-in functions (mysql_connect(), mysql_select_db() and mysql_query() (see http://www.php.net)), and this as your query:

PHP Code:

select count(*) from color_guide where name='john'




will not work ......

heres the problem


the script does not know who is the highest .......

thats what i want to find out


i want to know who is te highest by the amount of times there name is in new rows .
and what the count of rows for the highest poster is ......

Dean C 04-16-2004 03:32 PM

Use MAX instead of COUNT IIRC

teksigns 04-16-2004 03:34 PM

Quote:

Originally Posted by Dean C
Use MAX instead of COUNT IIRC


do you have a example

teksigns 04-16-2004 03:41 PM

here is a example database.

i have a table named

color_guide

with the following fields and data.

-------------------------------------------------
| poster | color | info | more info |
-------------------------------------------------
| john | blue | xx | xx |
| joe | black | xx | xx |
| chris | red | xx | xx |
| john | yellow | xx | xx |
| joe | xxxx | xx | xx |
| john | xxxx | xx | xx |
-------------------------------------------------

so in my sample database i need a query that will
check who has the most rows and display the count .

example :

John has 3 post

my username 04-16-2004 03:47 PM

Ok, i saw that i answered wrong question (read a little too fast) and deleted my post.
You were too quick for me...

Ok...I believe you may do it like this with mySQL:
(I've been working for 9 hours now, so it might not work :D)

PHP Code:

SELECT namecount(name) AS number FROM color_guide GROUP BY name ORDER BY number DESC LIMIT 1

Then you extract name and number from your result.
Example:

PHP Code:

$result mysql_fetch_object(mysql_query($query$dblink), MYSQL_ASSOC);
$highest $result->name;
$number $result->number



All times are GMT. The time now is 01:15 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.01032 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
  • (3)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)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