Facebook  Twitter 

SMFHacks.com

+-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 4257
Latest: Alex998.
New This Month: 1
New This Week: 0
New Today: 0
Stats
Total Posts: 43295
Total Topics: 7523
Most Online Today: 241
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 204
Total: 204

Author Topic: Custom Sort  (Read 4675 times)

0 Members and 1 Guest are viewing this topic.

Offline mashby

  • Jr. Member
  • **
  • Posts: 81
    • View Profile
    • ChopPix.com
Custom Sort
« on: May 27, 2008, 07:47:32 pm »
How could I sort the images in gallery based on a calculation (average rating)? Something like this where p.totalratings is the calculation.
Code: [Select]
case 'mostrated':

$sortby = 'p.totalratings';

break;

Also, what's the difference between sortby and sortby2?
Thanks,
mashby

Just to add more information, I'm running this code:
Code: [Select]
while($row = mysql_fetch_assoc($dbresult))
{
if ($row['totalratings']!=0)
$mashbynumber=($row['rating'] / ($row['totalratings']* 100) * 100);
else $mashbynumber='0.000001';
                 MORE CODE FROM HERE ON DOWN SHOWS IMAGES IN A SPECIFIC GALLERY

So, you can see that $mashbynumber is being reset for each image in the gallery. If I had X number of images in a gallery, how can I capture $mashbynumber and order the images descending based on the $mashbynumber for X number of images? I'm hoping to integrate this same logic in a phpbox on my home page as well.

Offline mashby

  • Jr. Member
  • **
  • Posts: 81
    • View Profile
    • ChopPix.com
Re: Custom Sort
« Reply #1 on: June 01, 2008, 10:14:31 pm »
Any ideas? An array?

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16452
    • View Profile
Re: Custom Sort
« Reply #2 on: June 02, 2008, 10:35:34 pm »
There is an avg function built into mysql
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_avg

$sortby holds the column to sort

$sortby2 is used to pass the column name page by page in a multi page setup.
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

 

Related Topics

  Subject / Started by Replies Last post
6 Replies
6674 Views
Last post November 11, 2006, 03:33:52 pm
by lotsawa
1 Replies
4010 Views
Last post December 10, 2006, 03:23:49 pm
by SMFHacks
5 Replies
7686 Views
Last post November 03, 2007, 07:40:56 pm
by SMFHacks
8 Replies
11335 Views
Last post October 01, 2011, 05:12:04 pm
by SMFHacks
1 Replies
3111 Views
Last post February 04, 2016, 07:37:39 am
by SMFHacks

+- Recent Topics

Please Help! by SMFHacks
April 17, 2024, 08:04:55 am

Rate own images by fvlog19
April 11, 2024, 10:56:53 am

Tidy Child Boards on 2.1.4 by SMFHacks
April 04, 2024, 03:54:12 pm

Problems SMF 2.0.19 > 2.1.4 SMF Gallery Pro - Recents Images to overall header by Michel68
March 30, 2024, 12:41:08 pm

Can't DROP 'id_member'; check that column/key exists Datei: by SMFHacks
March 30, 2024, 11:58:20 am

No thumbnails on new uploads by Tonyvic
March 29, 2024, 06:26:18 am

Display the Contact Page for guests by SMFHacks
March 27, 2024, 10:55:43 am

is it possible to add support for odysee.com by fvlog19
March 21, 2024, 08:47:51 am

Request for admin notification by davejo
March 10, 2024, 01:31:59 am

I need help with torrent upload by Ineedsmfhelp
March 09, 2024, 10:01:13 pm

Powered by EzPortal