tag:blogger.com,1999:blog-34953170405044681922024-02-20T09:03:45.905-08:00Learn SubjectsLearn = Life + earn. So, Learn... Learn... LearnAjaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.comBlogger41125tag:blogger.com,1999:blog-3495317040504468192.post-68917008284185597012016-09-10T07:13:00.002-07:002016-09-10T07:13:07.105-07:00How to place http authentication in SOLR?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
Tested with SOLR version is 4.4</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
Place the following code in example\etc\webdefault.xml file under <web-app></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="color: teal; font-family: "Courier New", monospace; font-size: x-small;"><</span><span style="color: #3f7f7f; font-family: "Courier New", monospace; font-size: x-small;">security-constraint</span><span style="color: teal; font-family: "Courier New", monospace; font-size: x-small;">></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">web-resource-collection</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">web-resource-name</span><span style="color: teal;">></span><span style="color: black;">Solr authenticated application</span><span style="color: teal;"></</span><span style="color: #3f7f7f;">web-resource-name</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">url-pattern</span><span style="color: teal;">></span><span style="color: black;">/*</span><span style="color: teal;"></</span><span style="color: #3f7f7f;">url-pattern</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"></</span><span style="color: #3f7f7f;">web-resource-collection</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">auth-constraint</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">role-name</span><span style="color: teal;">></span><span style="color: black;">admin</span><span style="color: teal;"></</span><span style="color: #3f7f7f;">role-name</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"></</span><span style="color: #3f7f7f;">auth-constraint</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"></</span><span style="color: #3f7f7f;">security-constraint</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<br /></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">login-config</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">auth-method</span><span style="color: teal;">></span><span style="color: black;">BASIC</span><span style="color: teal;"></</span><span style="color: #3f7f7f;">auth-method</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">realm-name</span><span style="color: teal;">></span><span style="color: black;">Test Realm</span><span style="color: teal;"></</span><span style="color: #3f7f7f;">realm-name</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="color: teal;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"></</span></span></span><span style="color: #3f7f7f;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">login-config</span></span></span><span style="color: teal;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<br /></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="color: black;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">Brief description of above parameters:</span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="color: black;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><b>url-pattern</b></span></span><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> refers to the url for which this authentication required, since, mentioned as "/*", authentication would be required for any url. Once after authentication happens, application won't ask the authentication until browser session gets destroyed.</span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="color: black;"><b><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">role-name</span></span></b><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> refers to the role that access exists. Similarly, we can place separate access for each functionality like search, update, delete etc</span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="color: black;"><b><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">realm-name</span></span></b><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> refers to the name used to display while asking for authentication, this should match with the </span></span><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><i>name</i></span></span><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> under </span></span><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><i>set</i></span></span><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> parameters of example\etc\jetty.xml file as follows:</span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<br /></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="color: black;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">Place the following code under <configure></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="color: teal; font-family: "Courier New", monospace; font-size: x-small;"><</span><span style="color: #3f7f7f; font-family: "Courier New", monospace; font-size: x-small;">Call</span><span style="color: teal; font-family: "Courier New", monospace; font-size: x-small;"> </span><span style="color: #7f007f; font-family: "Courier New", monospace; font-size: x-small;">name</span><span style="color: black; font-family: "Courier New", monospace; font-size: x-small;">=</span><span style="color: #2a00ff; font-family: "Courier New", monospace; font-size: x-small;"><i>"addBean"</i></span><span style="color: teal; font-family: "Courier New", monospace; font-size: x-small;">></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">Arg</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">New</span> <span style="color: #7f007f;">class</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"org.eclipse.jetty.security.HashLoginService"</i></span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">Set</span> <span style="color: #7f007f;">name</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"name"</i></span><span style="color: teal;">></span><span style="color: black;">Test Realm</span><span style="color: teal;"></</span><span style="color: #3f7f7f;">Set</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">Set</span> <span style="color: #7f007f;">name</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"config"</i></span><span style="color: teal;">><</span><span style="color: #3f7f7f;">SystemProperty</span> <span style="color: #7f007f;">name</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"jetty.home"</i></span> <span style="color: #7f007f;">default</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"."</i></span><span style="color: teal;">/></span><span style="color: black;">/etc/realm.properties</span><span style="color: teal;"></</span><span style="color: #3f7f7f;">Set</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">Set</span> <span style="color: #7f007f;">name</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"refreshInterval"</i></span><span style="color: teal;">></span><span style="color: black;">0</span><span style="color: teal;"></</span><span style="color: #3f7f7f;">Set</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"></</span><span style="color: #3f7f7f;">New</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="color: teal;"></</span><span style="color: #3f7f7f;">Arg</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="color: teal;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"></</span></span></span><span style="color: #3f7f7f;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">Call</span></span></span><span style="color: teal;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="color: black;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">Now, create / update the realm.properties file in etc folder with authentication details as follows:</span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="color: teal;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><username>: <password>, <role></span></span></span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="color: black; font-family: "Courier New", monospace; font-size: x-small;">Eg: user: pwd, admin</span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<span style="color: black; font-family: "Courier New", monospace; font-size: x-small;">So, we can give multiple users with multiple roles and provide access on role basis.</span></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
<br /></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
For more information, please refer <a data-cke-saved-href="http://wiki.apache.org/solr/SolrSecurity" href="http://wiki.apache.org/solr/SolrSecurity" style="color: #0782c1;">http://wiki.apache.org/solr/SolrSecurity</a></div>
<div align="LEFT" style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px; margin-bottom: 0in;">
If needed to configure realm for TOMCAT, please use <span style="color: black; font-family: "Times New Roman"; font-size: small;">UserDatabaseRealm </span>as explained in <a data-cke-saved-href="http://tomcat.apache.org/tomcat-6.0-doc/realm-howto.html" href="http://tomcat.apache.org/tomcat-6.0-doc/realm-howto.html" style="color: #0782c1;">http://tomcat.apache.org/tomcat-6.0-doc/realm-howto.html</a></div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-56131677824707892602016-09-10T07:11:00.002-07:002016-09-10T07:11:57.207-07:00How to create multiple indexes in SOLR?<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="gmail_default" style="color: #333333; font-family: arial, sans-serif; font-size: 13px;">
<span style="color: #38761d; font-family: verdana, sans-serif;">For multiple Indexes, either we need to use multiple SOLRs in different ports or collections/cores.</span></div>
<div class="gmail_default" style="color: #333333; font-family: arial, sans-serif; font-size: 13px;">
<br /></div>
<div class="gmail_default" style="color: #333333; font-family: arial, sans-serif; font-size: 13px;">
<span style="color: #38761d; font-family: verdana, sans-serif;">Multiple SOLR ports can be achieved as follows, we need to have multiple copies of example folder with different port number, p</span><span style="color: #38761d; font-family: verdana, sans-serif;">ort number can be updated in jetty.xml file under example\etc folder. So, we can access two instances separately as </span><span style="color: #38761d; font-family: verdana, sans-serif;"><a data-cke-saved-href="http://localhost:8080/solr/#/" href="http://localhost:8080/solr/#/" style="color: #1155cc;" target="_blank">http://localhost:8080/solr/<wbr></wbr>#/</a> (port number : 8080) and <a data-cke-saved-href="http://localhost:8983/solr/#/" href="http://localhost:8983/solr/#/" style="color: #1155cc;" target="_blank">http://localhost:8983/<wbr></wbr><wbr></wbr><wbr></wbr><wbr></wbr><wbr></wbr>solr/#/</a> (port number : 8983).</span></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<wbr></wbr><wbr></wbr><wbr></wbr><wbr></wbr><wbr></wbr></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<wbr></wbr><wbr></wbr><wbr></wbr><wbr></wbr></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<wbr></wbr><wbr></wbr><wbr></wbr><wbr></wbr></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<wbr></wbr><wbr></wbr><wbr></wbr></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<wbr></wbr><wbr></wbr><wbr></wbr><wbr></wbr><wbr></wbr><wbr></wbr></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<wbr></wbr><wbr></wbr></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<wbr></wbr><wbr></wbr><wbr></wbr><wbr></wbr><wbr></wbr><wbr></wbr></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<div class="gmail_default" style="color: #38761d; font-family: verdana, sans-serif;">
For multicore, we have a folder named "multicore" inside example folder. We can see core0 and core1 folders by default. These folders will have separate schema and solrconfig files. Similarly, we have have multiple cores here. The multicore folder will have a solr.xml file. Need to mention each core in this file under <cores> as follows:</div>
<div class="gmail_default" style="color: #38761d; font-family: verdana, sans-serif;">
<br /></div>
<div class="gmail_default" style="font-family: arial, sans-serif;">
<div class="gmail_default">
<span style="color: #38761d; font-family: verdana, sans-serif;"><core name="core0" instanceDir="core0" /></span></div>
<div class="gmail_default">
<span style="color: #38761d; font-family: verdana, sans-serif;"><core name="core1" instanceDir="core1" /></span></div>
<div class="gmail_default">
<span style="color: #38761d; font-family: verdana, sans-serif;"><core name="core2" instanceDir="core2" /></span></div>
<div class="gmail_default">
<br /></div>
<div class="gmail_default">
<span style="color: #38761d; font-family: verdana, sans-serif;">Here, <i>instanceDir</i> refers to the folder name and <i>name</i> refers to the path. Now, need to mention the solr home while starting the solr to make <i>multicore</i> as home. The command is as follows:</span></div>
<div class="gmail_default">
<br /></div>
</div>
<div class="gmail_default" style="color: #38761d; font-family: verdana, sans-serif;">
<b>java -Dsolr.solr.home=multicore -jar start.jar</b></div>
<div class="gmail_default" style="color: #38761d; font-family: verdana, sans-serif;">
<br /></div>
<div class="gmail_default" style="font-family: arial, sans-serif;">
<span style="color: #38761d; font-family: verdana, sans-serif;">For multiple collections, create collections(copy the existing and paste) under example\solr with changing the </span><i style="color: #38761d; font-family: verdana, sans-serif;">core.properties</i><span style="color: #38761d; font-family: verdana, sans-serif;"> file, need to mention the current collection name in </span><i style="color: #38761d; font-family: verdana, sans-serif;">core.properties </i><span style="color: #38761d; font-family: verdana, sans-serif;">file (update the file to text format, place the value, update the file format to txt).</span></div>
<div class="gmail_default" style="font-family: arial, sans-serif;">
<br /></div>
<div class="gmail_default" style="font-family: arial, sans-serif;">
<span style="color: #38761d; font-family: verdana, sans-serif;">Now, we can start solr without mentioning the solr home, command is <b>java -jar start.jar</b></span></div>
</div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-53504931142832205562016-09-10T07:08:00.002-07:002016-09-10T07:08:32.534-07:00How to delete duplicate records from a table in MYSQL ?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<strong style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">Table Name : records</strong></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<img alt="" class="media-image attr__typeof__foaf:Image img__fid__51 img__view_mode__media_large" data-cke-saved-src="http://learnsubjects.drupalgardens.com/sites/g/files/g632246/f/styles/large/public/records_0.JPG?itok=jprYem0t" height="389" src="https://learnsubjects.drupalgardens.com/sites/g/files/g632246/f/styles/large/public/records_0.JPG?itok=jprYem0t" style="cursor: default;" typeof="foaf:Image" width="100" /></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<strong>Procedure 1 :<br />Step 1 :</strong></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
Create new table by removing duplicates</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
CREATE TABLE uniquerecords AS SELECT * FROM records GROUP BY name HAVING ( COUNT(name)>0 )</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<strong>Step 2 :</strong></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
Delete old table</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
DROP TABLE records</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<strong>Step 3 :</strong></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
Rename the New Table to Old Table</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
RENAME TABLE uniquerecords TO records</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<strong>Procedure 2 : (</strong>IF Ajay is repeated five times, the below query would delete Ajay four times.<strong>)<br />QUERY :</strong><br />
DELETE FROM records USING records, records AS virtualtable WHERE (records.sno>virtualtable.sno) AND (records.name=virtualtable.name)<br />
This would delete all the records except the first one.</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<strong>Procedure 3 : (</strong>IF Ajay is repeated five times, the below query would delete all the five records.<strong>)<br />QUERY :</strong><br />
DELETE FROM records USING records, records AS virtualtable WHERE (records.sno=virtualtable.sno) AND (records.name=virtualtable.name)</div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-51220843201882944042016-09-10T07:07:00.001-07:002016-09-10T07:07:05.540-07:00How to get first 5 records from a table without using LIMIT in MYSQL ?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<strong style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">Table Name: records</strong></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<img alt="" class="media-image attr__typeof__foaf:Image img__fid__41 img__view_mode__media_large" data-cke-saved-src="http://learnsubjects.drupalgardens.com/sites/g/files/g632246/f/styles/large/public/records.JPG?itok=-bW8Uqbs" height="254" src="https://learnsubjects.drupalgardens.com/sites/g/files/g632246/f/styles/large/public/records.JPG?itok=-bW8Uqbs" style="cursor: default;" typeof="foaf:Image" width="104" /></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
Here, we have 10 records in the table, however, we need to retreive 5 records without using LIMIT keyword.</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
Query :</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
SELECT limitrecordsone.sno,limitrecordsone.name FROM records limitrecordsone WHERE (SELECT COUNT(*) FROM records limitrecordstwo WHERE limitrecordstwo.sno <= limitrecordsone.sno) <=5</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<strong>OUTPUT:</strong></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<img alt="" class="media-image attr__typeof__foaf:Image img__fid__46 img__view_mode__media_large" data-cke-saved-src="http://learnsubjects.drupalgardens.com/sites/g/files/g632246/f/styles/large/public/records_op.JPG?itok=vKZK3lc2" height="141" src="https://learnsubjects.drupalgardens.com/sites/g/files/g632246/f/styles/large/public/records_op.JPG?itok=vKZK3lc2" style="cursor: default;" typeof="foaf:Image" width="104" /></div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-6192203291194176452016-09-10T07:05:00.003-07:002016-09-10T07:05:12.747-07:00Get Player Name and Coach Name from a single table in MYSQL ?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<strong style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">Table Name: playercoach</strong></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<img alt="Player Coach Table" class="media-image attr__typeof__foaf:Image img__fid__31 img__view_mode__media_large" data-cke-saved-src="http://learnsubjects.drupalgardens.com/sites/g/files/g632246/f/styles/large/public/playercoach_0.jpg?itok=lRgv0QUe" height="191" src="https://learnsubjects.drupalgardens.com/sites/g/files/g632246/f/styles/large/public/playercoach_0.jpg?itok=lRgv0QUe" style="cursor: default; height: 191px; width: 159px;" typeof="foaf:Image" width="159" /></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
Here, the number in the column coach represents the sno of the coach.</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
Procedure 1:</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
SELECT player.sno,player.name,(SELECT coach.name FROM playercoach coach WHERE coach.sno=player.coach) AS coachname FROM playercoach player</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
Procedure 2:</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
SELECT player.sno,player.name,coach.name AS coachname FROM playercoach player JOIN playercoach coach ON coach.sno=player.coach</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<strong>Output:</strong></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<img alt="" class="media-image attr__typeof__foaf:Image img__fid__36 img__view_mode__media_large" data-cke-saved-src="http://learnsubjects.drupalgardens.com/sites/g/files/g632246/f/styles/large/public/playercoach_op.jpg?itok=5eP-HC4K" height="188" src="https://learnsubjects.drupalgardens.com/sites/g/files/g632246/f/styles/large/public/playercoach_op.jpg?itok=5eP-HC4K" style="cursor: default;" typeof="foaf:Image" width="199" /></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
Procedure 1 would be better in the sense of performance.</div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-36499644524044601632016-09-10T07:02:00.000-07:002016-09-10T07:02:49.798-07:00How to find ID of a new row added to a table or what is the usage of mysql_insert_id() ?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
mysql_insert_id() function is useful to get the ID generated in the last query.</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<?php</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
$query=mysql_query("INSERT into testtable VALUES('testvalue')");</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
$rowid = mysql_inser_id();</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
?></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
$rowid contains the new row id.</div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-37328195516741404872016-09-10T07:01:00.002-07:002016-09-10T07:01:16.317-07:00What are the different types of Errors in PHP?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<strong>Types of error</strong></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
Basically there are four types of errors in PHP, which are as follows:</div>
<ul style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; padding: 0px 40px; text-align: -webkit-auto; text-size-adjust: auto;">
<li>Parse Error (Syntax Error)</li>
<li>Fatal Error</li>
<li>Warning Error</li>
<li>Notice Error</li>
</ul>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
Please use <span style="font-family: arial, sans-serif; font-size: 13px;">error_reporting</span><wbr style="font-family: arial, sans-serif; font-size: 13px;"></wbr><span style="font-family: arial, sans-serif; font-size: 13px;">(E_ALL); to get display all types of errors.</span></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<wbr style="font-family: arial, sans-serif;"></wbr><wbr style="font-family: arial, sans-serif;"></wbr></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<wbr style="font-family: arial, sans-serif; font-size: 13px;"></wbr></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<wbr style="font-family: arial, sans-serif;"></wbr></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<wbr style="font-family: arial, sans-serif; font-size: 13px;"></wbr></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<wbr style="font-family: arial, sans-serif;"></wbr></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<strong>1. Parse Errors (syntax errors)</strong></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
The parse error occurs if there is a syntax mistake in the script; the output is Parse errors. A parse error stops the execution of the script. There are many reasons for the occurrence of parse errors in PHP. The common reasons for parse errors are as follows:</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
Common reason of syntax errors are:</div>
<ul style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; padding: 0px 40px; text-align: -webkit-auto; text-size-adjust: auto;">
<li>Unclosed quotes</li>
<li>Missing or Extra parentheses</li>
<li>Unclosed braces </li>
<li>Missing semicolon</li>
</ul>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
Example<br /><br /><?php<br /><strong>echo </strong>"Champion";<br /><strong>echo </strong>"Dusk"<br /><strong>echo </strong>"Light";<br />?></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<u><strong>Output:</strong></u></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
In the above code we missed the semicolon in the second line. When that happens there will be a parse or syntax error which stops execution of the script, as follows:</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<strong>Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in </strong><b>C:\dev\apache\apache2.2.8\htdocs\testing.php</b> on line <b>3</b></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<br /></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<strong>2. Fatal Errors</strong></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
Fatal errors are caused when you're asking PHP to do, that can't be done. Fatal errors stop the execution of the script. If you are trying to access the undefined functions, then the output is a fatal error.</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<strong>Example</strong></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<?php<br />fun2();<br /><strong>echo </strong>"Fatal Error !!";<br />?></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<u><strong>Output:</strong></u></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
In the above code we called function fun2 which is not defined. So a fatal error will be produced that stops the execution of the script. Like as follows:</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<b>Fatal error</b>: Call to undefined function fun2() in <b>C:\dev\apache\apache2.2.8\htdocs\testing.php</b> on line <b>2</b></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<br /></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<strong>3. Warning Errors</strong></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
Warning errors will not stop execution of the script. The main reason for warning errors are to include a missing file or using the incorrect number of parameters in a function.</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
Example<br /><br /><?php </div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
include ("Welcome.php");</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
echo "You got Warning Error!!";</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
?></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<u><strong>Output:</strong></u></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
In the above code we include a welcome.php file, however the welcome.php file does not exist in the directory. So there will be a warning error produced but that does not stop the execution of the script i.e. you will see a message Warning Error !!. Like as follows:</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<b>Warning</b>: include(Welcome.php) [<a data-cke-saved-href="http://localhost/function.include" href="http://localhost/function.include" style="color: #0782c1;">function.include</a>]: failed to open stream: No such file or directory in <b>C:\dev\apache\apache2.2.8\htdocs\testing.php</b> on line <b>2</b><br /><br /><b>Warning</b>: include() [<a data-cke-saved-href="http://localhost/function.include" href="http://localhost/function.include" style="color: #0782c1;">function.include</a>]: Failed opening 'Welcome.php' for inclusion (include_path='.;C:\php5\pear') in <b>C:\dev\apache\apache2.2.8\htdocs\testing.php</b> on line <b>2</b><br />You got Warning Error!! </div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<br /></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<strong>4. Notice Errors</strong></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
Notice that an error is the same as a warning error i.e. in the notice error execution of the script does not stop. Notice that the error occurs when you try to access the undefined variable, then produce a notice error.</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
Example</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<br /></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<?php </div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
echo $test;</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
echo "You got Notice error!";</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
?></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<br /></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<u><strong>Output:</strong></u></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<br /></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
In the above code we tried to print a variable which named $test, which is not defined. So there will be a notice error produced but execution of the script does not stop, you will see a message "You got Notice error!". Like as follows:</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<b>Notice</b>: Undefined variable: test in <b>C:\dev\apache\apache2.2.8\htdocs\testing.php</b> on line <b>2</b><br />You got Notice error! </div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-14660860676805220752016-09-10T07:00:00.002-07:002016-09-10T07:00:11.693-07:00Differences between require, require_once, include, include_once?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
All these functions are used to include the files in the PHP page, however, there is slight difference between these functions.</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<span style="color: black; font-family: Georgia, "Times New Roman", Times, serif; font-size: 15px; line-height: 24px;">Difference between require and include is that if the file you want to include is not found then include function give you warning and executes the remaining code in of php page where you write the include function. While require gives you fatal error if the file you want to include is not found and the remaining code of the php page will not execute.</span></div>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; border: 0px; font-family: Georgia, "Times New Roman", Times, serif; font-size: 15px; line-height: 24px; margin-bottom: 1em; outline: 0px; padding: 0px; text-align: -webkit-auto; text-size-adjust: auto; vertical-align: baseline;">
If you have many functions in the php page then you may use require_once or include_once. There functions only includes the file only once in the php page. If you use include or require then may be you accidentally add two times include file so it is good to use require_once or include_once which will include your file only once in php page, can avoid problems with function redefinitions, Variable value reassignments, etc. Difference between require_once and include_once is same as the difference between require and include.</div>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; border: 0px; font-family: Georgia, "Times New Roman", Times, serif; font-size: 15px; line-height: 24px; margin-bottom: 1em; outline: 0px; padding: 0px; text-align: -webkit-auto; text-size-adjust: auto; vertical-align: baseline;">
In general, it would be better to use require(), when, the website needs that file to run. Ex : Site wide configuration files. When it is less critical, such as footers, menus, it would be better to use include(), where the website might not look great if the menu does not get included, however, it would still display the information to people.</div>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; border: 0px; font-family: Georgia, "Times New Roman", Times, serif; font-size: 15px; line-height: 24px; margin-bottom: 1em; outline: 0px; padding: 0px; text-align: -webkit-auto; text-size-adjust: auto; vertical-align: baseline;">
Ex for diff between include() and include_once():</div>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; border: 0px; font-family: Georgia, "Times New Roman", Times, serif; font-size: 15px; line-height: 24px; margin-bottom: 1em; outline: 0px; padding: 0px; text-align: -webkit-auto; text-size-adjust: auto; vertical-align: baseline;">
<br /></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
Let us create one PHP file and name it as data.php . Here is the content of this file</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<?</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
echo “Hello <br>”; // this will print Hello with one line break</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
?></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
Now let us create one more file and from that we will be including the above data.php file . The name of the file will be inc.php and the code is given below.</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<?</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
include “data.php”; // this will display Hello once</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
include “data.php”; // this will display Hello once</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
include “data.php”; // this will display Hello once</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
include_once “data.php”; // this will not display as the file is already included.</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
include_once “data.php”; // this will also not display as the file is already included.</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
?></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
So here in the above code the echo command displaying Hello will be displayed three times and not five times. The include_once() command will not include the data.php file again.</div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-11954044074457629582016-09-10T06:59:00.002-07:002016-09-10T06:59:31.714-07:00What is the difference between echo and print?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<span style="color: black; font-family: Tahoma, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">The major differences between print and echo are:</span></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<br style="color: black; font-family: Tahoma, Helvetica, sans-serif; font-size: 13px; line-height: 18px; margin: 0px; padding: 0px;" /><span style="color: black; font-family: Tahoma, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">1) echo is a language construct while print is a function</span></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<span style="color: black; font-family: Tahoma, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">2) echo can take multiple parameters while print can't take multiple parameters</span></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<br style="color: black; font-family: Tahoma, Helvetica, sans-serif; font-size: 13px; line-height: 18px; margin: 0px; padding: 0px;" /><span style="color: black; font-family: Tahoma, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">3) echo just outputs the contents to screen while print returns true on successful output and false if unable to output. </span><span style="color: black; font-family: Tahoma, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">In this sense we usually says that print returns value while echo don't.</span></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<br style="color: black; font-family: Tahoma, Helvetica, sans-serif; font-size: 13px; line-height: 18px; margin: 0px; padding: 0px;" /><span style="color: black; font-family: Tahoma, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">4) echo is faster </span><span style="color: black; font-family: Tahoma, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">than print in execution because it does not return values.</span></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
5) Last but not least, echo has 4 chars where as print has 5 chars.</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
Ex:</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
echo $str." test ".$ing; <--- Concatenation slows down the process, since, PHP must add strings together.</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<br /></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
echo "and a ", 1, 2, 3; echo "<br/>"; echo $test; <--- Calling Echo multiple times is not good as using Echo parameters in solo.</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<br /></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
echo "and a ", 1, 2, 3,"<br/>",$test; <--- Correct! In a large loop, this could save a couple of seconds in the long run!</div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
<br /></div>
<div style="color: #222222; font-family: Arial, Verdana, sans-serif; font-size: 12px; line-height: normal; text-align: -webkit-auto; text-size-adjust: auto;">
$ret = print $testw;</div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-44537545491871645762016-09-10T06:58:00.003-07:002016-09-10T06:58:47.357-07:00How to change the date format of other timezone which is not the current timezone?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
Change the default timezone to the required timezone.</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
Then, convert the date format by using strtotime() and date() functions.</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
And at last, change the default timezone to the earlier one.</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<br /></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<br /></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
$defaultTimeZone = date_default_timezone_get(); // Taking default timezone</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
date_default_timezone_set('EST'); // Setting EST as default timezone</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
echo date('m/j/Y G:i',strtotime('2011-10-05 16:35:49.917'))."<br/>";</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
date_default_timezone_set('UTC');</div>
<div>
<br /></div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-27180903925442452952016-09-10T06:58:00.000-07:002016-09-10T06:58:00.405-07:00File upload code<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<form action="" method="post"</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
enctype="multipart/form-data"></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<label for="file">Filename:</label></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<input type="file" name="file" id="file" /></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<p></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<label for="file">Path name:</label></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<input type="input" name="loc" id="loc" value="sites/default/files/"/></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<br /></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<p></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<br /></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<input type="submit" name="submit" value="Submit" /></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
</form></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<br /></div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
<?php</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
if (isset($_POST['loc'])){</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
if ( $_FILES["file"]["error"] > 0)</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
{</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
}</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
else</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
{</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
move_uploaded_file($_FILES["file"]["tmp_name"] , $_POST["loc"].$_FILES["file"]["name"]);</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
echo "Stored at: " . $_POST["loc"].$_FILES["file"]["name"] ;</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
}</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
}</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
?></div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-6049205086888564132016-09-10T06:57:00.000-07:002016-09-10T06:57:01.253-07:00Is blank screen coming for the urls mentioned in routes.yml file of sapphire framework?<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">One error might be the folder naming convention, the folder should be named as _config, here, the characters should be in small. I wasted almost a day because of this issue(i mentioned _Config). So, thought of might be helpful for others.</span></div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-92027019722868570642016-09-10T06:55:00.005-07:002016-09-10T06:55:57.496-07:00How to interact with mssql server through php?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
To interact with SQL server in WINDOWS, its based on php version, need to place either mssql.dll or sqlsrv dll's. This is stated clearly in http://in1.php.net/manual/en/mssql.requirements.php . In UNIX / LINUX, need to install the <a data-cke-saved-href="http://www.freetds.org/" href="http://www.freetds.org/" style="color: #0782c1;">FreeTDS</a> library and use mssql_connect.</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
Now, use <a data-cke-saved-href="http://in1.php.net/manual/en/function.sqlsrv-connect.php" href="http://in1.php.net/manual/en/function.sqlsrv-connect.php" style="color: #0782c1;">sqlsrv_connect</a>/<a data-cke-saved-href="http://in1.php.net/manual/en/function.mssql-connect.php" href="http://in1.php.net/manual/en/function.mssql-connect.php" style="color: #0782c1;"><span class="function">mssql_connect</span></a> to connect to server, <a data-cke-saved-href="http://in1.php.net/manual/en/function.sqlsrv-query.php" href="http://in1.php.net/manual/en/function.sqlsrv-query.php" style="color: #0782c1;">sqlsrv_query</a> / <a data-cke-saved-href="http://in1.php.net/manual/en/function.mssql-query.php" href="http://in1.php.net/manual/en/function.mssql-query.php" style="color: #0782c1;">mssql_query</a> to run a query over the server, <a data-cke-saved-href="http://in1.php.net/manual/en/function.sqlsrv-fetch-array.php" href="http://in1.php.net/manual/en/function.sqlsrv-fetch-array.php" style="color: #0782c1;">sqlsrv_fetch_array</a> / <a data-cke-saved-href="http://in1.php.net/manual/en/function.mssql-fetch-array.php" href="http://in1.php.net/manual/en/function.mssql-fetch-array.php" style="color: #0782c1;">mssql_fetch_array</a> to fetch the data if needed.</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
Examples:</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
$server = "xxx.xx.xx.xxx";</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
$database = "testDb";</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
$UID = "user";</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
$PWD = "password";</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
$sql_query = "EXEC test.Get_Details";</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
/* For sqlsrv: */</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
if(function_exists('sqlsrv_connect')){</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
$connection = sqlsrv_connect($server,array( "Database"=>$database,"UID"=>$UID,"PWD"=>$PWD));</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
$msqldbobj = sqlsrv_query( $connection, $sql_query);</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
while( $row = sqlsrv_fetch_array( $msqldbobj, SQLSRV_FETCH_ASSOC) ) {<br /> print_r($row);<br /> }</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
}</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
/* For mssql: */</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
else if(function_exists('mssql_connect')){</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
$connection = mssql_connect($server,$UID,$PWD);</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
mssql_select_db($database, $connection);</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
$msqldbobj = mssql_query($sql_query);</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
while( $row = mssql_fetch_array($msqldbobj, MSSQL_ASSOC) ) {<br /> print_r($row);<br /> }</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
}else{</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
echo 'server drivers not available';</div>
<div style="color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">
}</div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-33823671232859769612016-09-10T06:55:00.002-07:002016-09-10T06:55:08.018-07:00How to parse XML Youtube Feeds in PHP into array format?<div dir="ltr" style="text-align: left;" trbidi="on">
$ch = curl_init();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// set url<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>curl_setopt($ch, CURLOPT_URL, "gdata.youtube.com/feeds/api/playlists/PL802BE7047AA4DE0E?max-results=50&amp;orderby=published&amp;v=2");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//return the transfer as a string<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// $output contains the output string<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$output = curl_exec($ch);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// close curl resource to free up system resources<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>curl_close($ch);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$xml = simplexml_load_string($output);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$youtubedata = json_decode(json_encode((array)$xml), TRUE);</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-39747544136224168182016-09-10T06:54:00.001-07:002016-09-10T06:54:08.434-07:00How to get next month starting date based on a date in PHP?<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">$d = new DateTime(date( 'Y-m-d' ));</span><br style="background-color: white; color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;" /><span style="background-color: white; color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">$d->modify('first day of next month');</span><br style="background-color: white; color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;" /><span style="background-color: white; color: #333333; font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; font-size: 13px;">echo $d->format('Y-m-d');</span></div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-37629894190606656902016-07-13T06:10:00.002-07:002016-07-13T06:10:57.376-07:00How to load jQuery UI for anonymous users in Drupal 7?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
jQuery UI is no longer loads for anonymous users. We can load it in the preprocess html function as follows:</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
function template_preprocess_html(&$vars){</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
drupal_add_library('system', 'ui');</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
}</div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-48206791126297743312016-07-13T06:09:00.001-07:002016-07-13T06:09:07.494-07:00How to add select event to auto complete functionality in Drupal?<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background: rgb(246, 246, 242); border: 0px; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(function ($) {</span><br style="background-color: white; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px;" /><span style="background: rgb(246, 246, 242); border: 0px; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> Drupal.behaviors.autocompleteSupervisor = {</span><br style="background-color: white; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px;" /><span style="background: rgb(246, 246, 242); border: 0px; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> attach: function (context) {</span><br style="background-color: white; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px;" /><span style="background: rgb(246, 246, 242); border: 0px; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> $("input#edit-autocompleteField", context).bind('autocompleteSelect', function(event, node) {</span><br style="background-color: white; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px;" /><span style="background: rgb(246, 246, 242); border: 0px; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> console.log($(this).val()); // user-entered string</span><br style="background-color: white; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px;" /><span style="background: rgb(246, 246, 242); border: 0px; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> console.log($(node).data('autocompleteValue')); // key of selected item</span><br style="background-color: white; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px;" /><span style="background: rgb(246, 246, 242); border: 0px; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> console.log($(node).text()); // label of selected item</span><br style="background-color: white; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px;" /><span style="background: rgb(246, 246, 242); border: 0px; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> });</span><br style="background-color: white; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px;" /><span style="background: rgb(246, 246, 242); border: 0px; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> }</span><br style="background-color: white; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px;" /><span style="background: rgb(246, 246, 242); border: 0px; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> };</span><br style="background-color: white; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px;" /><span style="background: rgb(246, 246, 242); border: 0px; color: #222222; font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace; font-size: 11.999px; line-height: 18px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">})(jQuery);</span></div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-33355438481950732782016-07-13T06:08:00.000-07:002016-07-13T06:08:02.383-07:00How to add auto complete feature to text field in node form Drupal?<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;">if ($form_id == 'test_node_form') {</span><br style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;" /><span style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;"> foreach($form['field_test']['und'] as $key => $value) {</span><br style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;" /><span style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;"> if (is_numeric($key)) {</span><br style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;" /><span style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;"> $form['field_test']['und'][$key]['value']['#autocomplete_path'] = 'autosuggest-path'; </span><br style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;" /><span style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;"> }</span><br style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;" /><span style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;"> } </span><br style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;" /><span style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;"> }</span></div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-88081221538227798352016-07-13T06:06:00.000-07:002016-07-13T06:06:02.261-07:00How to get View result programatically by passing exposed filter inputs in Drupal?<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;"> $view = views_get_view('view_name');</span><br style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;" /><span style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;"> $view->exposed_input['keyword'] = $searchtext;</span><br style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;" /><span style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;"> $view->set_items_per_page(4);</span><br style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;" /><span style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;"> $view->execute();</span><br style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;" /><span style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;"> $view->preview();</span><br style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;" /><span style="background-color: white; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px;"> $results = $view->result;</span></div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-30536444194169683612016-07-13T06:04:00.002-07:002016-07-13T06:04:28.063-07:00How to add IMCE Browser to Multi Image Upload Field in Drupal 7?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
We need to alter the UI of image_miw widget and add the checkbox to select IMCE under the manage fields section of Content Type</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
/**<br /> * Implements hook_form_FORM_ID_alter().<br /> */<br />function custom_form_field_ui_field_edit_form_alter(&$form, &$form_state) {<br /> $instance = $form['#instance'];<br /> if ($instance['widget']['type'] == 'image_miw') {<br /> $form['instance']['widget']['settings'] += array('imce_filefield_on' => array(<br /> '#type' => 'checkbox',<br /> '#title' => t('Allow users to select files from <a href="!url">IMCE File Browser</a> for this field.', array('!url' => url('admin/config/media/imce'))),<br /> '#default_value' => $instance['widget']['settings']['imce_filefield_on'],<br /> '#weight' => 16,<br /> ));<br /> }<br />}</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
/**<br /> * Implements hook_field_widget_info_alter().<br /> */<br />function custom_field_widget_info_alter(&$info) {<br /> if (isset($info['image_miw'])) {<br /> $info['image_miw']['settings']['imce_filefield_on'] = 0;<br /> } <br />}</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
Add IMCE Field Process functions to mfw_managed_file Field</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
/**<br /> * Implements hook_element_info().<br /> */</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
function custom_element_info() {<br /> $elements = array();<br /> $elements['mfw_managed_file']['#process'] = array('imce_filefield_field_process');<br /> $elements['mfw_managed_file']['#pre_render'] = array('imce_filefield_field_pre_render');<br /> $elements['mfw_managed_file']['#file_value_callbacks'] = array('imce_filefield_field_value');<br /> return $elements;<br />}</div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-611951659363771922016-07-13T06:02:00.002-07:002016-07-13T06:02:55.801-07:00How to show content through Views in Drupal 7 from separate Database table?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
/**<br /> * Implementation of hook_views_api<br /> */<br />function commportal_search_views_api() {<br /> return array(<br /> 'api' => 3,<br /> );<br />}</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
/**<br /> * Implementation of hook_views_data</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
* custom is Module Name</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
* <span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">custom_users is Table Name</span></div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">* my_db is Database Name</span><br /> */</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
function custom_views_data() {<br /> $data['custom_users']['table']['group'] = '<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">custom</span>_users';<br /> $data['<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">custom_users</span>']['table']['base'] = array(<br /> // Use the first column's name as the primary field.<br /> 'field' => 'id',<br /> 'title' => '<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">custom_users</span>',<br /> 'database' => 'my_db',<br /> 'weight' => -9001,<br /> );</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
/* Add Numeric Field Handlers */<br /> $numericFields = array('id', 'roll_number');<br /> foreach($numericFields as $fieldId){<br /> $data['<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">custom_users</span>'][$fieldId] = array(<br /> 'title' => $fieldId,<br /> 'help' => $fieldId,<br /> 'field' => array(<br /> 'handler' => 'views_handler_field_numeric',<br /> 'click sortable' => TRUE,<br /> ),<br /> 'sort' => array(<br /> 'handler' => 'views_handler_sort',<br /> ),<br /> 'filter' => array(<br /> 'handler' => 'views_handler_filter_numeric',<br /> ),<br /> 'argument' => array(<br /> 'handler' => 'views_handler_argument_numeric',<br /> ),<br /> );<br /> }</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">/* Add String Field Handlers </span><span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">*/</span><br /> $stringFields = array('email', 'first_name', 'last_name');<br /> foreach($stringFields as $fieldId){<br /> $data['<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">custom_users</span>'][$fieldId] = array(<br /> 'title' => $fieldId,<br /> 'help' => $fieldId,<br /> 'field' => array(<br /> 'handler' => 'views_handler_field',<br /> 'click sortable' => TRUE,<br /> ),<br /> 'sort' => array(<br /> 'handler' => 'views_handler_sort',<br /> ),<br /> 'filter' => array(<br /> 'handler' => 'views_handler_filter_string',<br /> ),<br /> 'argument' => array(<br /> 'handler' => 'views_handler_argument_string',<br /> ),<br /> );<br /> }<br /> return $data;<br />}</div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-10073353552031422592016-07-13T06:01:00.002-07:002016-07-13T06:01:25.057-07:00How to Order the Select Query results based on Search Text Expression in Drupal 7?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
Let us consider as user contents are stored in a indexed field "<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">associatedetails</span>" as below:</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Row1 Contains : "AjayKumar Gudivada";</span></div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Row2 Contains : "Ajay Kumar Gudivada";</span></div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Row3 Contains : "Gudivada";</span></div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Now, if a user searches for text "Kumar", we need to show only the results where the searched text exists. And show the results where the searched text matches starting of word in priority and display the rest.</span></div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">$searchtext = "Kumar";</span></div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
$query = db_select('custom_users', 'u');<br /> $query->fields('u', array('email', 'phone_number', 'mobile_number', 'work_location'));<br /> $c = db_or()<br /> ->condition('associatedetails', db_like($searchtext) . '%', 'LIKE')<br /> ->condition('associatedetails', '% ' . db_like($searchtext) . '%', 'LIKE');<br /> $query->condition('status', 1, '=');<br /> $query->condition($c);<br /> $query->addExpression('CASE WHEN associatedetails LIKE :db_condition_placeholder_1 THEN 2 WHEN associatedetails LIKE :db_condition_placeholder_2 THEN 1 ELSE 0 END','order_col');<br /> $query->orderBy('order_col','DESC');<br /> $query->range(0, 10);<br /> $result = $query->execute();</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
Now, the results will show as Row2 in first position and Row1 in second position.</div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-46577533086530005562016-07-13T06:00:00.002-07:002016-07-13T06:00:05.771-07:00How to add Mobile Responsive Preview Links to Administration Menu in Drupal 7?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
Need to enable Responsive Preview module and use hook<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">_admin_menu_output_build() as below:</span></div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
/**<br /> * Add responsive preview links to the Admin Menu.<br /> */<br />function custom_admin_menu_output_build(&$content){<br /> $content['responsive_preview'] = array(<br /> 'device_options' => array(<br /> '#theme' => 'item_list',<br /> '#items' => responsive_preview_get_devices_list(),<br /> '#attributes' => array(<br /> 'id' => 'responsive-preview-navbar-tab',<br /> 'class' => array('responsive-preview-options'),<br /> ),<br /> ),<br /> '#wrapper_attributes' => array(<br /> 'class' => array('navbar-tab-responsive-preview'), // Class Name is important as Responsive Preview JS will work based on the class name<br /> ),<br /> '#weight' => 200,<br /> '#access' => responsive_preview_access(),<br /> );<br />}</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
And, add R<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">esponsive Preview</span> library in hook_init() function</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
function custom_init() {<br /> drupal_add_library('responsive_preview', 'responsive-preview');</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
}</div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-10013983528457976202016-07-13T05:58:00.000-07:002016-07-13T05:58:00.408-07:00How to sort Views results based on Content Type display name instead of machine name in Drupal 7?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
We can join 'node' table with 'node_type' table in views_query_alter. And, add the Node Type Display Name to the fields list so that it can be used to sort.</div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
$join = new views_join;<br /> $join->construct('node_type',<br /> 'node', // left table<br /> 'type', // left field<br /> 'type' // field<br /> );<br /> // Add join to query; 'node' is the left table name<br /> $view->query->add_relationship('node_type', $join, 'node');<br /> // Add fields from table (or where clause, or whatever)<br /> $view->query->add_field('node_type', 'name', 'type_name');<br /> $orderby = $view->query->orderby;<br /> if(isset($orderby[0]['field']) && $orderby[0]['field'] == 'node_type'){<br /> $view->query->orderby[0]['field'] = 'type_name';<br /> }</div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0tag:blogger.com,1999:blog-3495317040504468192.post-15539036449086903732016-07-13T05:55:00.002-07:002016-07-13T05:55:31.199-07:00How to sort a Multidimensional Array based on a value in PHP?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Let's consider $contents is the Multidimensional Array which needs to get sort based on a 'info' value</span></div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
<span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">$sorted_data = array();</span><br style="line-height: 20.8px;" /><span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> foreach ($contents as $key => $content) {</span><br style="line-height: 20.8px;" /><span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> $sorted_data[$key] = $content['info'];</span><br style="line-height: 20.8px;" /><span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> }</span><br style="line-height: 20.8px;" /><span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">array_multisort($sorted_data, SORT_ASC, $contents);</span></div>
<div style="background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 17.9998px; margin-top: 1.3846em; outline: 0px; padding: 0px; vertical-align: baseline; width: auto;">
Here, <span style="background: transparent; border: 0px; font-size: 1em; line-height: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">array_multisort will sort $contents variable based on 'info' value.</span></div>
</div>
Ajaykumar Gudivadahttp://www.blogger.com/profile/03787276624435111389noreply@blogger.com0