Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-05-23 04:19:54

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

jmd_count: Count MySQL tables

Download 0.1.1

Pretty simple plugin – count MySQL table rows and optionally evaluate them in a conditional.

(Split from jmd_dashboard).

Last edited by jm (2008-05-23 16:08:24)

Offline

#2 2008-05-23 11:46:03

Ruhh
Member
From: dakota dunes
Registered: 2008-01-20
Posts: 305

Re: jmd_count: Count MySQL tables

Neato.

I used the first function to count articles, comments, etc. :)


<txp:Ruhh />

Offline

#3 2008-05-23 11:50:44

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: jmd_count: Count MySQL tables

Yeah, nice one jm. Very useful, thanks.

Out of curiosity, was there a reason you wrote your own SQL statement in the code instead of using safe_count()?

Last edited by Bloke (2008-05-23 12:22:22)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2008-05-23 12:20:32

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: jmd_count: Count MySQL tables

Wow, jm! Didn’t expect it so quickly! Good to have it!
In the help’s example you use it for statistics. I could imagine it as something more valuable: For a small business, if stocks go below n, automatically send «Go baking!» mail to the bakery at OnUnload. Or similar, if site comments begin to pile up, red warning lamps could flash on the dashboard/assistant slave is skyped up ;)

Thanks, jm!


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#5 2008-05-23 12:27:01

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: jmd_count: Count MySQL tables

Ah, sorry missed the “ridonkulous” example.
Would you please be so kind and explain a little more on

<txp:jmd_count_value/> Returns the value from jmd_if_count.

Where is it necessary/different from jmd_count?


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#6 2008-05-23 12:31:04

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: jmd_count: Count MySQL tables

uli wrote:

Where is it necessary/different from jmd_count?

When you use jmd_if_count it sets a global variable on the page with the return value of the specified count. jmd_count_value simply retrieves that value of the “last if” in case you need it later on the page as well as the conditional behaviour.

Last edited by Bloke (2008-05-23 12:31:36)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#7 2008-05-23 13:39:47

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: jmd_count: Count MySQL tables

Thanks, Stef! Figured it out in the meantime, but can’t get if_count working.

I’m using exactly the same WHERE phrase as in a working instance of jmd_count:
<txp:jmd_if_count eval=">5" table="textpattern" where="image != ''">More than 5 images used in articles</txp:jmd_if_count /> (Rather useless stuff, but … well, for training ;) It doesn’t output the enclosed content, in no constellation of >5, <5, =5. It complains about the unexpected equal-sign/T_string (IS) or does nothing, whereas if_count seems to give me the total amount of articles. Am I missing something from the plugin help again?


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#8 2008-05-23 13:59:37

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: jmd_count: Count MySQL tables

Uli, that cannot be parsed correctly by the tag parser in TXP 4.0.6 and earlier. (will work in 4.0.7)
The > before the 5 will close the tag prematurely.

Also, this: </txp:jmd_if_count /> should be </txp:jmd_if_count>

Offline

#9 2008-05-23 14:02:33

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: jmd_count: Count MySQL tables

</txp:jmd_if_count />

ooOOPPS! =)

Edit: I developed the minimal parser: Removing the second slash shows all the fine errors you’d expect it would :))

Last edited by uli (2008-05-23 14:05:35)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#10 2008-05-23 16:08:09

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: jmd_count: Count MySQL tables

Bloke wrote:

Out of curiosity, was there a reason you wrote your own SQL statement in the code instead of using safe_count()?

Just in case users want to count a whole table without a where clause – it’s unfortunate that safe_count and safe_rows have where hardcoded :(.

uli wrote:

<txp:jmd_if_count eval=">5" table="textpattern" where="image != ''">More than 5 images used in articles</txp:jmd_if_count />

Make sure those columns actually exist (hint: execute describe textpattern from a MySQL client).

ruud wrote:

Uli, that cannot be parsed correctly by the tag parser in TXP 4.0.6 and earlier. (will work in 4.0.7)
The > before the 5 will close the tag prematurely.

It’s all your fault Ruud! I just love the new tag parser :).

I’ve updated the plugin to 0.1.1 with 4.0.6 compatibility. Uli, use eval="&gt;5".

Offline

#11 2008-05-23 16:30:47

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: jmd_count: Count MySQL tables

jm wrote:

Make sure those columns actually exist (hint: execute describe textpattern from a MySQL client).

I didn’t employ smd_query previously ;) So “image” exists in “textpattern”, yes.

I’ve updated the plugin to 0.1.1 with 4.0.6 compatibility. Uli, use eval="&gt;5".

Sorry for all that hassle, but I’m really grateful that you did :)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#12 2008-05-23 17:00:57

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: jmd_count: Count MySQL tables

uli wrote:

So “image” exists in “textpattern”, yes.

Ah right, I forgot article_image is just called Image. Self: read your own hint!

Sorry for all that hassle, but I’m really grateful that you did :)

It was only one line, so it’s not a big deal. Enjoy!

Offline

Board footer

Powered by FluxBB