Adding an array in a SQL query
leefish Offline
Hamster
*****
Posts: 1,009
Joined: Apr 2010
Post: #11
RE: Adding an array in a SQL query
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.


[Image: leelink.gif]
MYBB1.6 & XThreads
11-02-2010 07:32 PM
Visit this user's website Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #12
RE: Adding an array in a SQL query
Congrats for your plugin, Lee Smile

11-03-2010 07:31 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Online
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #13
RE: Adding an array in a SQL query
(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.')');


My Blog
11-03-2010 08:08 AM
Find all posts by this user Quote this message in a reply
leefish Offline
Hamster
*****
Posts: 1,009
Joined: Apr 2010
Post: #14
RE: Adding an array in a SQL query
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.



Attached File(s) Thumbnail(s)
   


[Image: leelink.gif]
MYBB1.6 & XThreads
(This post was last modified: 11-03-2010 08:11 AM by leefish.)
11-03-2010 08:08 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Online
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #15
RE: Adding an array in a SQL query
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.


My Blog
11-03-2010 10:11 AM
Find all posts by this user Quote this message in a reply
leefish Offline
Hamster
*****
Posts: 1,009
Joined: Apr 2010
Post: #16
RE: Adding an array in a SQL query
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


[Image: leelink.gif]
MYBB1.6 & XThreads
11-04-2010 09:37 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Online
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #17
RE: Adding an array in a SQL query
Nice, you got a release.  Thanks for sharing leefish! Smile

My Blog
11-04-2010 02:19 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: