PDA

View Full Version : Selecting the Strongest Character?


kaotic
05-28-2004, 02:21 PM
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
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
I couldn't find the solution there - think you could just hook me up with the query?

Try this:


$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:


$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 :)