MyBB Hacks

Full Version: Adding an array in a SQL query
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi Zinga

Thank you for the "review" and the help Smile It was silly of me not to do the db escape string - and I had seen it used in one of RateU's plugins as well (facepalm).

The aggregated download count is working correctly now, so thats a good thing too. I will go and do some research on adding up fields with php.

I will give it some thought on the method to select the attachments to use - its just a shame that I can't share it as it is, so I will have a go at the suggested alternative solution...one step at a time though.
Congrats for your plugin, Lee Smile
(11-02-2010 07:32 PM)leefish Wrote: [ -> ]I will give it some thought on the method to select the attachments to use - its just a shame that I can't share it as it is, so I will have a go at the suggested alternative solution...one step at a time though.
Can just have a setting for that, then stick them in the query.

Eg, comma delimited setting:

PHP Code:
$fields = $db->escape_string($mybb->settings['something']);
$fields = '"'.strtr($fields, array(' ' => '', ',' => '","')).'"';

$query = $db->query('... a.field IN ('.$fields.')');

And I am back Smile  I have found how to add up the columns in php, I used this in my query loop and added the variables into the templates:

Code:
			$total_downloads += my_number_format($mdx['downloads']);
			$total_replies += my_number_format($mdx['replies']);
			$total_views += my_number_format($mdx['views']);


but now I have a new problem. It seems that the numbers are too big for the fields. Its not the column width, I checked that, but if you look at the views total (on the screenshot I have marked it with a red box) then there is a problem - a problem that is not there with the comments.

(The grey bits are where I blocked users names for privacy and whatnot)

EDIT: I was typing so I missed RateUs post -  thanks RateU, and thanks to all for the congratulations etc - its great to have finally made something for myself, no matter how small Smile

And then I missed Zinga's too - yes, a setting is a good plan. I will look into that.

Don't use my_number_format when adding up values.  You need to keep it numerical - my_number_format converts numbers into textual format for display purposes.

So you'd have:

PHP Code:
            $total_downloads += $mdx['downloads'];
            $total_replies += $mdx['replies'];
            $total_views += $mdx['views'];

And run everything through my_number_format after the end of the loop.

Ok, I have this available over on LeeFish for free download - you also don't need to register to get it. Its not sorting yet (will update later) but is customisable regarding what field keys you want to display the downloads of from the ACP.

Xthreads Upload Stats
Nice, you got a release.  Thanks for sharing leefish! Smile
Pages: 1 2
Reference URL's