Zend Framework with MySQL "SELECT" - php

I am using zend framework, and I need to add option "where", which include commas (") it is used for filtering, tried to use it in html:
<option value=""msg":"Paid""><?php echo Core_Locale::translate('Paid')?></option>
But after turning on other page filter disappear. What I need to get using this:
{"success":true,"version":"1.0","paid":false,"added_to_balck_list":true,"msg":"Paid"}
I'm sure to get msg using fetchall and select each which is equal, but in table is tones of data and I won't use it. So guys may be you know how I can add commas in "where"?
$select->where( "response like '%$message%'");
In SQL, it should look like:
response like "msg":"Paid"
But I can't just type like %paid% because every record have Paid:true of paid paid:false and I get all the records.

Related

Algolia highlighting in Laravel 5.3

I am using Laravel 5.3 and Algolia,
I want to highlight the search result,I read the documentation but I still don't know how to do it.
https://www.algolia.com/doc/api-client/php/parameters#attributestohighlight
Any ideas?
When search results are returned from Algolia, they will wrap the "highlighted part" with <em> </em> tags by default. This happens right out of the box, so all you really need to do is use CSS to customize the look of <em>s within your search results div to get the effect you want.
Of course if you prefer that they wrap highlighted text in something other than <em> then you can customize it with anything you wish (such as maybe a span tag with a "highlighted-search" class or something). You customize this when initializing the search in your PHP.
$index = $client->initIndex('contacts');
$result = $index->search('search query', ['attributesToRetrieve' => 'firstname,lastname', 'hitsPerPage' => 50, 'highlightPreTag' => '<span class="highlighted-search">', 'highlightPostTag' => '</span>']);
Now let's say you search 'John D' and submit that search query. Algolia will return a string to the effect of:
<span class="highlighted-search">John D</span>oe
Now with your CSS you customize it like
span.highlighted-search {
background-color:yellow;
}
and now it will highlight the search query with yellow.
Of course this is all assuming you want the static (PHP Library) server side search results. I highly recommend that you use the autocomplete.js library so you can get live search results as you type. This requires using the js libraries to return results client-side while the user types. It is a much better experience.
In each item returned by the search engine, there is an extra "_highlightResult" attribute that contains some metadata and the value of the searchable attributes modified with search terms surrounded with <em>.
For instance, for the search term "toux", the returned JSON will looks like:
{
"medicament" : "VICKS TOUX SECHE 7,33 mg ADULTES MIEL, pastille",
"_highlightResult" : {
"medicament" : {
"value" : "VICKS <em>TOUX</em> SECHE 7,33 mg ADULTES MIEL, pastille",
"matchedWords" : ["toux"]
....
...
}
To highlight the search results, with the search terms, you simply have to display the attribute value under "_highlightResult" instead of the raw one.
If you are not using it already, I would recommend you to use Instantsearch.js.
Highlighting the typed keywords of the search results is dealt whitin the hits widget the same way, in its templates.item parameter.
You may find live code example of this feature here https://community.algolia.com/instantsearch.js/examples/

Accessing XML attributes data

I have two lines of XML data that are attributes but also contain data inside then and they are repeating fields. They are being stored in a SimpleXML variable.
<inputField Type="Name">John Doe</inputField>
<inputField Type="DateOfHire">Tomorrow</inputField>
(Clearly this isnt real data but the syntax is actually in my data and I'm just using string data in them)
Everything that I've seen says to access the data like this, ,which I have tried and it worked perfectly. But my data is dynamic so the data isn't always going to be in the same place, so it doesn't fit my needs.
$xmlFile->inputField[0];
$xmlFile->inputField[1];
This works fine until one of the lines is missing, and I can have anywhere from 0 to 5 lines. So what I was wondering was is there any way that I can access the data by attribute name? So potentially like this.
$xmlFile->inputField['Name'];
or
$xmlFile->inputField->Name;
I use these as examples strictly to illustrate what I'm trying to do, I am aware that neither of the above lines of code are syntactically correct.
Just a note this information is being generated externally so I cannot change the format.
If anyone needs clarification feel free to let me know and would be happy to elaborate.
Maybe like this?
echo $xmlFile->inputField->attributest()->Name;
And what you're using? DOMDocument or simplexml?
You don't say, but I assume you're using SimpleXMLElement?
If you want to access every item, just iterate:
foreach ($xmlFile->inputField as $inputField) { ... }
If you want to access an attribute use array notation:
$inputField['Type']
If you want to access only one specific element, use xpath:
$xmlFile->xpath('inputField[#Type="Name"]');
Perhaps you should read through the basic examples of usage in the SimpleXMLElement documentation?
For example you can a grab a data:
$xmlFile = simplexml_load_file($file);
foreach($xmlFile->inputField as $res) {
echo $res["Name"];
}

Get raw code from Comments in ExpressionEngine

How can I get the raw code of a comment in ExpressionEngine (frontend)?
The thing is this: If a comment contains Code or HTML like [quote]-Tags, the ee-native {comment}-Tag renders this as <blockquote>Life is like a box of… … but how can I get the raw code like [quote]Life is like a box of…?
I'm currently working on a Quote-Feature (frontend/JavaScript) for native EE comments. Till now I've worked with jQuery.text() or .html() … but both ways you get no tag (.text()) or html-tags (.html()).
Isn't there a way to get the raw comment code (for example into a data-attribute or script-tag) to later use with JavaScript?
Edit (1): I've tried SQL — is this the only/best way to do this?
<blockquote data-raw="{exp:query sql="SELECT exp_comments.comment AS comment_raw FROM exp_comments WHERE exp_comments.comment_id = {comment_id} "}{comment_raw}{/exp:query}">
{comment}
</blockquote>
Edit (2): The SQL works fine, but if there is a " inside the raw comment code, the whole thing breaks because the browser thinks this is the closing quote of the «data-raw»-attribute :-/ Is there a Way to 'mask' all characters? (" and ' and < and > etc.)
Edit (3): I now use a <script>-Tag to insert the {comment_raw}-code, this way the characters do not disturb.
You'd probably be better off retrieving the raw comment via an ajax call rather than adding a query for every single comment on the page. You'd avoid the performance hit and wouldn't need to worry about storing large strings in data attributes. I'd probably do something like this:
Create a new 'get_comment' template containing the {exp:query} tag with WHERE comment_id = '{segment_X}'
When a user hits the reply/quote button use jQuery.get() to send a request to your get_comment template, passing in the comment_id based on a data-commentid attribute on the reply button.
Update your input's value with the .get() response.

Structuring a Gdata Spreadsheet query

I am trying to build a Zend_Gdata_Spreadsheets_ListQuery and I can't find any references that explain what the expected query syntax is and what types of queries you can and cannot perform. The closest I have been able to come to finding anything is the [Google Data APIs Client Library (1.41.1)] (https://developers.google.com/gdata/javadoc/com/google/gdata/client/spreadsheet/ListQuery#ListQuery(java.net.URL)), which describes the function setSpreadsheetQuery as follows:
setSpreadsheetQuery
public void setSpreadsheetQuery(java.lang.String query) Sets the
structured spreadsheet query. Parameters: query - the query such as
"name = 'Sonja' and state = 'Georgia'"
This works just fine if you are looking for a cell whose column title is "name" and that contains the text "Sonja"—and nothing else. I am looking for cells containing "Sonja" as part, of the cell's text. A cell in the "name" column with the value "Sonja the Awesome" for example, would not match the search above. name=Sonya* causes an error and name="Sonya*" returns no results.
So, does anybody know where I can find a rundown of what the expected "structure" for the "structured spreadsheet query" is?
Have you tried using regex ? Also, make sure to escape the regex special characters.
Something like \bSonja\b

How to Extract Data from a field with multiple values?

IP.Nexus puts custom fields into a table all muddled up into one row and some how pulls the correct data out.
basically my custom fields row looks like so:
a:2:{i:2;s:4:"Test";i:3;s:10:"Accounting";}
How do i select what item to pull as i would like to out put just one item not the whole row, is it with delimiters or string splitter, as i am novice with this part of mySQL
Cause i would like to echo out just the advertising on its own and also vice versa for the testing.
Thanks in advance
It's a serialized array using serialize() function so you can get its contents using unserialize($YourString);.
But I see that you string is corrupted for deserialization, because s:4: in s:4:"advertising" says that after s:4: 4 character long string is expected that advertising is not.
The data in the database is in serialized(json) form.You can turn it into simple array using unserialize.
For example;if $mystr is your string
write
$mystring=unserialize($mystring)
You will get normal array of this string
You can do
foreach($mystring as $str){
$ads[]=$str['advertising'];
}
and the resulting array $ads will be the ads you like in simple array form
Since this looks as JSon, you can use a PHP JSon module to parse each row from MySQL.
<?php
(...)
while (...) {
$obj = json_decode($row);
// do something with $obj
}

Categories