Textpattern CMS support forum

You are not logged in. Register | Login | Help

#241 2010-06-13 21:45:21

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,493
Website

Re: smd_query: Talk to the database directly via SQL

the_ghost wrote:

Does the plugin supports breaking query in lines?

I don’t think the plugin cares. But the TXP parser might complain or interpret it wrongly, especially given that you have a “closing tag” character in the COUNT(*)>4 line.

But having said that, I’ve used multi-line things in smd_xml for the ‘source’ attribute and the parser has held up fine — and that attribute contained XML markup with < and > symbols in it.

Hmmm, are you writing this tag in an article or a Form? If in an article, is it set to Leave text untouched? Does it work if you put it in a Form and call it with <txp:output_form/> or the override_form?

Last edited by Bloke (2010-06-13 21:45:40)


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

#242 2010-07-05 11:04:58

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 344
Website

Re: smd_query: Talk to the database directly via SQL

Sorry if the question has already been asked, I can’t find any answer right now (I began using TXP 1 month ago, until then I always found answers … but not now).

Here is my problem : I would like to retrieve the email of an article’s author to re-inject in zem_contact_reborn.
What is written for the moment :

<txp:smd_query column="email" table="txp_users" where="RealName=' _I_don_t_know_what_to_put_here_ '">
    <txp:zem_contact to="{email}" label="" thanks_form="f_zem_ok" form="f_zem_contact" />
</txp:smd_query>

Thanks in advance.

[Edited for code display — Stef]

Last edited by Bloke (2010-07-05 11:09:41)

Offline

#243 2010-07-05 11:15:01

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,493
Website

Re: smd_query: Talk to the database directly via SQL

CeBe wrote:

I would like to retrieve the email of an article’s author to re-inject in zem_contact_reborn.

If you are in an individual article context then you should be able to use <txp:author /> to get the current article author’s real name and pass that along. Something like this (untested) :

<txp:smd_query column="email" table="txp_users" where='RealName="<txp:author />"'>
    <txp:zem_contact to="{email}" label="" thanks_form="f_zem_ok" form="f_zem_contact" />
</txp:smd_query>

If you’re not viewing an article then it’s somewhat trickier!

EDIT: added missing quotes, d’oh

Last edited by Bloke (2010-07-05 11:16:02)


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

#244 2010-07-05 12:07:33

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 344
Website

Re: smd_query: Talk to the database directly via SQL

(Thanks for fixing the display, I just didn’t understand well how to post code)

Ok … that’s what I tried first, but didn’t notice that I had just before a self-closing article tag. So I wasn’t in an article context, right ? And of course it didn’t work.

As I have 2 articles in this page (first live, second sticky), I put the contact form in the second article before displaying the body, and
- it’s ok, just have to pay attention to the ‘ and “
- body displays live article instead of sticky (o_O)

… sigh … I must have missed something that is not related to smd_query.
Back in the documentation and/or find another way.

Anyway, thank you, it seems to be the right solution.

Offline

#245 2010-08-31 08:40:41

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 355
Website

Re: smd_query: Talk to the database directly via SQL

Thank you for very useful plugin!
Possibly it will be comfortably to add the attribute ID in smd_query.

patch for smd_query 0.41

 --replace--
                'class' => '',
                'debug' => '0',
--to--
                'class' => '',
                'id' => '',
                'debug' => '0',
--and replace--
        $finalout[] = doLabel($label, $labeltag).doWrap(array_merge($colout, $out), $wraptag, $break, $class);
--to--
        $finalout[] = doLabel($label, $labeltag).doWrap(array_merge($colout, $out), $wraptag, $break, $class,'','','',$id);

patch for smd_query 0.21

 --replace--
                'class' => '',
                'debug' => '0',
--to--
                'class' => '',
                'id' => '',
                'debug' => '0',
--and replace--
        return doLabel($label, $labeltag).doWrap(array_merge($colout,$out), $wraptag, $break, $class);
--to--
        return doLabel($label, $labeltag).doWrap(array_merge($colout,$out), $wraptag, $break, $class,'','','',$id);

aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

#246 2010-08-31 09:01:04

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 355
Website

Re: smd_query: Talk to the database directly via SQL

PHP4 fix – replace function stripos to function preg_match

patch for smd_query 0.41

--replace--
               $mode = ($mode == 'auto') ? ((stripos($query, "SELECT") === 0) ? 'output' : 'input') : $mode;
--to--
                $mode = ($mode == 'auto') ? ((preg_match('/(select|show) /i', $query)) ? 'output' : 'input') : $mode;

Upd: small fix

Last edited by makss (2010-08-31 09:52:36)


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

#247 2010-08-31 09:28:25

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,493
Website

Re: smd_query: Talk to the database directly via SQL

Thanks makss. Next version now has:

  • support for TXP tags inside the container under certain conditions
  • html_id attribute
  • breakclass attribute
  • fix for PHP 4 compatibility (oops, sorry)
  • mode is correctly set as ‘output’ when either SELECT or SHOW query types are used

Final testing in progress.


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

#248 2010-08-31 09:48:09

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 355
Website

Re: smd_query: Talk to the database directly via SQL

Thanks Bloke.

Another idea for simple creation table header, add attributes:

colshead = "field1|field2|sometext1|..."
colshead_delim = "|"

It will be generate code

<thead><tr><th>field1</th><th>field2</th><th>sometext1</th><th>...</th></tr></thead>

.

Upd: Maybe it useful… :)

patch for smd_query 0.41

--replace--
		'colsform' => '',
		'escape' => '',
--to--
		'colsform' => '',
		'colshead' => '',
		'colshead_delim' => '|',
		'escape' => '',
--and replace--
			if ($out) {
--to--
			if ($out) {
				if ($colshead) {
					$colout[] = '<th>'.str_replace($colshead_delim, '</th><th>', $colshead).'</th>';
				}

It’s generate output:

<tr><th>field1</th><th>field2</th><th>sometext1</th><th>...</th></tr>

Last edited by makss (2010-08-31 10:36:23)


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

#249 2010-08-31 20:58:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,493
Website

Re: smd_query: Talk to the database directly via SQL

v0.5 is released

  • form now overrides container
  • container’s <txp:else /> tag can be applied to forms (see example 14 in the plugin help)
  • populate attribute : support for TXP tags inside the container under certain conditions (thanks atbradley)
  • html_id attribute (thanks makss)
  • breakclass attribute
  • fix for PHP 4 compatibility (thanks makss)
  • mode is correctly set as ‘output’ when either SELECT or SHOW query types are used

Hope that helps a few folk out to do some further crazy SQL skulduggery.


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

#250 2010-10-28 14:31:20

aslsw66
Member
From: Geneva, Switzerland
Registered: 2004-08-04
Posts: 338
Website

Re: smd_query: Talk to the database directly via SQL

Is there any way to iterate across the results from smd_query and conditionally set an output based on the result?

Here’s what I’m now trying to do…

With your help, I have now set up an area in a password protected section where nominated users can add items to a table (in both senses – a database table, and a table presented on the web page). These users can also delete from the table, and of course edit an existing entry in a table.

One of the items is selectable from a select input. If they are creating a new entry, then the select defaults to the first option. Unfortunately, this is the same if they are editing an existing entry.

What I would really like is for the select input to default to the previously stored entry. Now, I know that smd_query can extract multiple values and iterate over them for the sake of pagination. But what I want to do is to check the result of each row and then set the default attribute for the matching option.

I thought I could do it with some of the {smd_rows} but my brain has run out of ideas.

Does that make sense? Or am I trying to push smd_query beyond its natural limits?

Thanks

Offline

Board footer

Powered by FluxBB