Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#217 2010-03-18 07:53:54

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,703
Website

Re: smd_query: Talk to the database directly via SQL

dinoact, that’d make a nice “this time last year…” txptip for (photo)blog authors with lots of posts.


TXP Builders – finely-crafted code, design and txp

Offline

#218 2010-03-24 09:34:39

mlarino
Member
Registered: 2007-06-29
Posts: 367

Re: smd_query: Talk to the database directly via SQL

Stef! thanks for that intro on how to format the pagination, but I was working on it and just found a little problem with your plugin.

When I navigate to page 2 of the pagination smd_query creates, it ads /?pg=2 to the URL and it messes up my CSS and my JS
When I remove manually the slash / it all works ok.

You can test it in www.mlarino.com/asesoria/inmobiliaria
make a search of “todos” and “todos” (then when you see the map click on “ver todos” on the right side and you will get the results with pagination.

Dont know why it messes up the CSS or JS of top of the site but, is there a way to remove that / from the code?
thanks!

Offline

#219 2010-03-24 10:31:43

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

Re: smd_query: Talk to the database directly via SQL

mlarino wrote:

is there a way to remove that / from the code?

Have you tried putting a <txp:permlink /> inside the anchor tags before the ?pg= bits? Not sure if it’ll work but it might.


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

#220 2010-03-24 11:09:48

mlarino
Member
Registered: 2007-06-29
Posts: 367

Re: smd_query: Talk to the database directly via SQL

Bloke wrote:

Have you tried putting a <txp:permlink /> inside the anchor tags before the ?pg= bits? Not sure if it’ll work but it might.

<txp:permlink /> ? I dont understand, and what do you mean with anchor tags? the /?pg= is generated by smd_querys pagination…

When I see the list of articles and click on NEXT> I reach http://www.mlarino.com/asesoria/resultado-fichas/?pg=2

That Slash in /?pg=2 is what is wrong.

Last edited by mlarino (2010-03-24 11:10:51)

Offline

#221 2010-03-24 11:20:10

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

Re: smd_query: Talk to the database directly via SQL

mlarino wrote:

what do you mean with anchor tags? the /?pg= is generated by smd_querys pagination…

Are you using that huge wodge of code I posted above? The ?pg= part is generated by that, not smd_query. As an example, the last part reads:

<txp:smd_query_if_next>
<a href="?pg={smd_nextpage}"><b>NEXT</b></a>
<txp:else />
NEXT
</txp:smd_query_if_prev>

I was just wondering if the browser or TXP was adding the slash automatically for some reason, so perhaps hardcoding the URL like this might fix it:

<txp:smd_query_if_next>
<a href="<txp:permlink />?pg={smd_nextpage}"><b>NEXT</b></a>
<txp:else />
NEXT
</txp:smd_query_if_prev>

?

Last edited by Bloke (2010-03-24 11:21:10)


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

#222 2010-03-24 11:20:55

mlarino
Member
Registered: 2007-06-29
Posts: 367

Re: smd_query: Talk to the database directly via SQL

Oh wait! :)

think I got what you meant.

<txp:smd_query_if_prev> <a href="<txp:permlink />?pg={smd_prevpage}"> Previous {smd_rows_prev}</a> </txp:smd_query_if_prev> <txp:smd_query_if_next> <a href="<txp:permlink />?pg={smd_nextpage}"> Next {smd_rows_next}</a> </txp:smd_query_if_next>

It works!

Offline

#223 2010-03-24 11:23:13

mlarino
Member
Registered: 2007-06-29
Posts: 367

Re: smd_query: Talk to the database directly via SQL

I was using this before:

Page {smd_thispage} of {smd_pages} | Showing records {smd_row_start} to {smd_row_end} of {smd_allrows} | <txp:older>Next {smd_rows_next}</txp:older> | <txp:newer>Previous {smd_rows_prev}</txp:newer>

that was giving me the / before ?pg=2

Offline

#224 2010-03-24 11:29:18

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

Re: smd_query: Talk to the database directly via SQL

mlarino wrote:

It works!

Great! I’ve no idea why the slash gets added in some circumstances. Probably something simple that I don’t understand about URIs. If anybody knows…


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

#225 2010-04-09 14:29:13

jens31
Plugin Author
From: munich / dtschermani
Registered: 2008-08-25
Posts: 183
Website

Re: smd_query: Talk to the database directly via SQL

hii

i have a small problem, and i dont know if this is solvable, or if i have to regret right now.
but i think its possible..

so
i have a multilingual website and its using one db with 2 txps, one for each language.
now my client wants to have one section where users can leave their comments.
and he wants them visible in both languages. so (i guess) there would be one way to hardcode the path to the specific db entry..(hopefully?? [never did that, yet])
or maybe this plugin can do the job..? is it possible to call another db / suffix via this tool..?

thanks for your help

best
jens

Offline

#226 2010-04-19 01:26:45

atbradley
Plugin Author
From: Rhode Island, US
Registered: 2007-02-15
Posts: 34
Website

Re: smd_query: Talk to the database directly via SQL

Bloke,

I made a minor change to my copy of smd_query—don’t know if you’d be interested.

Basically, I already had an article form when changing project requirements meant I needed more query power than article_custom could give me, so I hacked smd_query to let me use an article (or link or file) form with it. I added a new argument, “datatype”, which can be set to ‘file’, ‘link’, or ‘article’ to populate the appropriate global variable for each result row from your query.

This is the file.

And here’s a diff:

2a3
>     global $thisfile, $thislink;
33a35
>         'datatype' => '',
187a190,207
>
>                 if ( 'article' == $datatype ) {
>                     populateArticleData($row);
>                     $thisarticle['is_first'] = ($page_rowcnt == 1);
>                     $thisarticle['is_last'] = (($page_rowcnt + 1) == $pagerows);
>                 }
>                 if ( 'file' == $datatype ) { $thisfile = file_download_format_info($row); }
>                 if ( 'link' == $datatype ) {
>                     $thislink = array(
>                     'id'          => $row['id'],
>                     'linkname'    => $row['linkname'],
>                     'url'         => $row['url'],
>                     'description' => $row['description'],
>                     'date'        => $row['uDate'],
>                     'category'    => $row['category'],
>                 );
>                 }
>
301c321
< }?>
\ No newline at end of file
---
> }
\ No newline at end of file

Offline

#227 2010-04-19 08:10:33

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

Re: smd_query: Talk to the database directly via SQL

atbradley wrote:

I made a minor change to my copy of smd_query—don’t know if you’d be interested.

Yes, interested. Thanks for the idea. It does make things cleaner and also gives the ability to use either the replacement tags or standard TXP tags (or a mixture).

To do it fully is not quite as simple as your version unfortunately because we need to remember the previous state of the globals and reinstate them after smd_query has finished meddling, ortherwise it trashes your current article/file/link context. I’d also add in support for the new $thisimage context in the current SVN.

In fact I’d probably go so far as to auto-detect the datatype based on the current context — e.g. if $thisimage, $thisfile or $thislink are set, use that relevant context, else default to $thisarticle — but allow you to override it in case the plugin got it wrong (probably only if you were embedding images inside files inside links or something mad like that).

Let me look into this and make an official release based on your mod sometime this week. Thanks again.

jens31

Sorry for missing your question. The plugin just assumes you have a connection to a database already instated. If that database has more than one TXP install inside it, the plugin doesn’t care so you can — as you suggest — hard-code the prefix in your queries. Alternatively, set up a txp:variable to store your prefix (you can probably read the language from some place that indicates the current user language pref and make a decision based on that) and put that in your queries instead. Hope that helps.

Last edited by Bloke (2010-04-19 08:13:31)


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

#228 2010-04-19 13:04:54

atbradley
Plugin Author
From: Rhode Island, US
Registered: 2007-02-15
Posts: 34
Website

Re: smd_query: Talk to the database directly via SQL

Bloke wrote:

To do it fully is not quite as simple as your version unfortunately because we need to remember the previous state of the globals and reinstate them after smd_query has finished meddling, ortherwise it trashes your current article/file/link context. I’d also add in support for the new $thisimage context in the current SVN.

Right. I hadn’t thought about people using it within an existing article/whatever context. Is it adequate just to say

$thisarticle_orig = $thisarticle; $thisfileorig = $thisfile; $thislinkorig = $thislink;

at the top of smd_query() and then swap them back before the end?

In fact I’d probably go so far as to auto-detect the datatype based on the current context — e.g. if $thisimage, $thisfile or $thislink are set, use that relevant context, else default to $thisarticle — but allow you to override it in case the plugin got it wrong (probably only if you were embedding images inside files inside links or something mad like that).

I’m not clear how this works—wouldn’t you need to check for the existence of specific fields in the query result before feeding rows into $thiswhatever? I’m not using smd_query inside an existing article/file/link context, I’m using it to replace the built-in tags that can’t quite do what I need them to.

Offline

Board footer

Powered by FluxBB