How to create a quote encased variable from another variable.

Author Message

steve walker

Monday 04 October 2004 5:32:07 am

Hi there,

This is a new thread coming out of:

http://www.ez.no/community/forum/developer/dynamic_fetch_using_simple_form

I'm trying to encase a variable in quotes for fetch purposes... the eind result I' m after is:

let x=example
let encased_x='$x'
so that the value of $encased_x is 'example'

Paul B had given me some pointers but I wasnt able to get this working - does anyone have a past example or some ideas on this one?

Many thanks, Steve.

http://www.oneworldmarket.co.uk

Paul Forsyth

Monday 04 October 2004 5:51:52 am

Try:

{let x=example
     encased_x=concat('',$x)}

paul

steve walker

Monday 04 October 2004 7:05:28 am

Paul,

Thanks for the reponse.

I tried the code, but it doesnt make any change - my variable stays the same. The full code I have is:

{let carat=ezhttp( 'search_carat', 'get' )}
{let clarity=ezhttp( 'search_clarity', 'get' )}

{let carat_in='('|concat($carat,')') 
let ecarat_in=concat('',$carat_in)

let clarity_in='('|concat($clarity,')')
let exactresults=fetch(content,tree,hash(parent_node_id, 59, 
attribute_filter,  
array(and,array('stone_product/carat','in','$carat_in'), 
array('stone_product/clarity','in','$clarity_in'))))
}
ecarat is {$ecarat_in} and clarity is {$clarity_in}

The line "{let carat_in='('|concat($carat,')')" encases the variable in brackets - perhaps I could introduce the quote here at the same time, but attempts so far have failed...

Of all the characters, the quote mark seems the most difficult to get in there.

Regards, Steve.

http://www.oneworldmarket.co.uk

Paul Forsyth

Monday 04 October 2004 7:52:07 am

Steve,

Could you show before and after text of what you want to achieve?

Paul

Paul Borgermans

Monday 04 October 2004 10:31:12 am

OK, The quotes are a bit difficult to generate. You will need additional concat("'") to make sure the strings are quoted inside the "array" (actually a string which build a SQL array like thing).

I upgraded kernel/classes/ezcontentobjecttreenode.php to version 3.4.2 (actually, the most recent in stable, but it works in 3.4.2).

Extra with this update: two more filter operators: between and not_between for integer/float ranges.

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

steve walker

Tuesday 05 October 2004 6:59:32 am

Paul B,

Are you sure this fetch will work with alpahnumeric characters? I've been tryin get this to work just with static info.... even if I use your example:

let exactresults=fetch(content,tree,hash(parent_node_id, 59, 
attribute_filter,  
array(and,array('stone_product/carat','in','paul%'), 
array('stone_product/clarity','in',$clarity_in))))
}

I still get:

Query error: You have an error in your SQL syntax.  
Check the manual that corresponds to your MySQL server version for the right syntax 
to use near 'paul% AND a1.sort_key_string IN  (2) ) AND 

If I change the line to:

array(and,array('stone_product/carat','in','(2)'), 

It works, but putting alphanumerics in as:

'(a)' or '('a')'

Gives sql or 'too many character' errors.

Could you let me know what I'm missing here?

Thanks, Steve.

http://www.oneworldmarket.co.uk

Paul Borgermans

Tuesday 05 October 2004 7:54:13 am

Hi Steve

I overlooked the fact that filtervalue strings are escaped in kernel/classes/ezcontentobjecttreenode.php

I corrected this in pubsvn and uploaded the corrected file in the contributions.

A working example in a production site here is as follows, and note the complicated concat to create the string:

{let myinstring=concat("('",'WP1.1',"','",'WP6.1',"')")
      test_fetch=fetch(content,tree,hash(parent_node_id,2,attribute_filter,array(OR,array('task/acronym','in',$myinstring))))}

My inistring: {$myinstring}
<ul>
{section loop=$test_fetch var=test}
<li>{$test.name}</li>
{/section}
</ul>
{/let}

hth

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

steve walker

Tuesday 05 October 2004 9:38:15 am

Paul,

Finally got this working :)))) - the code I have to wrap the variable in the quotes etc is:

{let carat_in=concat("('",$carat,"')") 

Thanks for the help.

Steve.

http://www.oneworldmarket.co.uk

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.