Jump to content

Grouping Items in PHP?


dual_alliance

Recommended Posts

I'm just wondering how do l go about grouping simliar objects that are returned from a MySQL query.

Example:
Book x 8
Chain x 9
etc..

I've looked on google for grouping things in PHP but l cant find anything.

I have also thought about using the COUNT(*) query in MySQL, but does it work in while loops and count every single item in that loop?

Thanks for your help.
Link to comment
https://forums.phpfreaks.com/topic/34396-grouping-items-in-php/
Share on other sites

Here is a list of all the rows and what they do:

i_unique_id <- make sure their is no multiple entries
i_id <- the item id, if you had a wooden stick they would all have an item id of 9.  While a baseball bat would all have an id of 15.
i_owner <- explains its self.
i_cat <- catagory its in
i_name <- explains its self.
i_picture <- explains its self.
i_for <- what type it is, e,g weapon, book, armour.
i_c_price <- custom price is some one wants to sell it
i_b_price  <- price they buy it for
i_s_price <- how much they can sell it for if they sell it back to the shop
i_multiplyer <- if the item is a weapon how much damage it does.
Link to comment
https://forums.phpfreaks.com/topic/34396-grouping-items-in-php/#findComment-161889
Share on other sites

That is basically the same thing l came up with, thanks for your help HuggieBear.

The code l used was:

[code]
$query = "SELECT `i_unique_id`, `i_name`, `i_s_price`, COUNT(i_id) FROM `mitems` WHERE `i_owner` = '$userid' AND `i_for` = '2' GROUP BY `i_name`";
$result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());
[/code]

And the outcome:
[img]http://img147.imageshack.us/img147/2725/here12te3.jpg[/img]
Link to comment
https://forums.phpfreaks.com/topic/34396-grouping-items-in-php/#findComment-161912
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.