vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Selecting the Strongest Character? (https://vborg.vbsupport.ru/showthread.php?t=65605)

kaotic 05-28-2004 02:21 PM

Selecting the Strongest Character?
 
I've got somewhat of an RPG system going on, and I want to select and display the strongest member from a table.

I think it should look something like...

$strongguy = $DB_site->query("SELECT * FROM table ORDER BY column DESC LIMIT 1");

After which, I would put {$strongguy['name'} in the template, but I seem to get some kind of resource error each time. Is something wrong with my query?

Dark_Wizard 05-28-2004 04:03 PM

Quote:

Originally Posted by kaotic
I've got somewhat of an RPG system going on, and I want to select and display the strongest member from a table.

I think it should look something like...

$strongguy = $DB_site->query("SELECT * FROM inferno_user ORDER BY str DESC LIMIT 1");

After which, I would put {$strongguy['name'} in the template, but I seem to get some kind of resource error each time. Is something wrong with my query?

Yes there is something wrong...look closely at your query...how does your query know which person is the strongest?

If you can't figure out what you need I will post it but just trying to help you learn...

kaotic 05-28-2004 04:27 PM

Eh, I'm not sure how to select the highest value of a field. I'm guessing I need something about "WHERE", but I wouldn't know. Any knowledge I have of this is based on other hacks I've installed, and I don't see a similiar query anywhere.

Care to elaborate for me?

Dark_Wizard 05-28-2004 04:39 PM

Try this link => http://us3.php.net/max

kaotic 05-28-2004 05:04 PM

I couldn't find the solution there - think you could just hook me up with the query?

Dark_Wizard 05-28-2004 06:01 PM

Quote:

Originally Posted by kaotic
I couldn't find the solution there - think you could just hook me up with the query?

Try this:

PHP Code:

$strongguy $DB_site->query("
                        SELECT name, str
                        FROM inferno_user
                        WHERE str = MAX(str)"
); 


kaotic 05-28-2004 09:24 PM

I tried that query earlier, it says something about an invalid group function use.

Brad 05-28-2004 10:21 PM

use this:

PHP Code:

$array $DB_site->query_first("SELECT * FROM table ORDER BY powerfield DESC LIMIT 1"); 


Xenon 05-29-2004 12:17 PM

yes, Brad is correct, you have to use query_first, as this would return an array, query() just returns a mysql result pointer :)


All times are GMT. The time now is 02:27 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.01216 seconds
  • Memory Usage 1,728KB
  • 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
  • (9)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