drupal_json($output); used to send server side responses in Drupal. Here to process html responses from an array in $.ajax success() we need to use eval() in order to handle encrypted responses. Following is the sample code.
<?php
$output['FirstTable'] = "<table><tr><td>1</td></tr></table>";
$output['SecTable'] = "<table><tr><td>2</td></tr></table>";
echo drupal_json($output); exit;
?>
In Script file
$.ajax({
"url": <url>,
"success": function(output) {
var content = eval("(" + output + ")"); // response is converted as object
$("selector").html(content.FirstTable);
$("selector").html(content.SecTable);
}
});
Drupal and PHP related posts - Drupal Chennai, Navaneethakrishnan.R
Monday, February 6, 2012
Friday, February 18, 2011
Drupal form_set_error: Set error in two fields and display error message once
When we face an issue for highlighting two fields with one validation message. Please do follow the below steps.
<?php
function <custom>_validate($form) {
form_set_error("<fieldname1>","Please check your entry");
form_set_error("<fieldname2>","Please check your entry");
array_pop($_SESSION['messages']['error']);
}
?>
<?php
function <custom>_validate($form) {
form_set_error("<fieldname1>","Please check your entry");
form_set_error("<fieldname2>","Please check your entry");
array_pop($_SESSION['messages']['error']);
}
?>
Friday, July 2, 2010
PDF to SWF converstion through PHP
I want to share this to you all. I was struct to convert PDF to SWF from PHP using EXEC() function. Problem i faced is the folder name with white spaces. I was tried all the poosibilities. Finally I catch the solution. The code i used is
<?php
// Syntax: exec('path_to_exe "path_to_source_PDF_file" -o "path_to_converting_swf_file"');
// I missed the double codes (") in the path_to_source_PDF_file and path_to_converting_swf_file. Hence the conversion not happened.
// Example: [ I used SWFtools to convert PDF o SWF]
exec("C:\\SWFTools\\pdf2swf.exe c:\\test.pdf -o C:\\navneeth.swf");
?>
I hope this will help to someone.
<?php
// Syntax: exec('path_to_exe "path_to_source_PDF_file" -o "path_to_converting_swf_file"');
// I missed the double codes (") in the path_to_source_PDF_file and path_to_converting_swf_file. Hence the conversion not happened.
// Example: [ I used SWFtools to convert PDF o SWF]
exec("C:\\SWFTools\\pdf2swf.exe c:\\test.pdf -o C:\\navneeth.swf");
?>
I hope this will help to someone.
Wednesday, April 21, 2010
Drupal Site offline page theme
To enable offline theme add the following line in settings.php
<?php
$conf['maintenance_theme'] = '<themename>';
?>
Now the site is ready with offline theme. Drupal provides contributed offline theme to use. Click here http://ftp.drupal.org/files/projects/offline-6.x-1.1.tar.gz to download offline theme.
<?php
$conf['maintenance_theme'] = '<themename>';
?>
Now the site is ready with offline theme. Drupal provides contributed offline theme to use. Click here http://ftp.drupal.org/files/projects/offline-6.x-1.1.tar.gz to download offline theme.
Monday, November 2, 2009
Keep in mind when using Left Join
The WHERE clause would be false in the following query if tableB.column1 were NULL:
SELECT * FROM tableA LEFT JOIN tableB ON (column1) WHERE tableB.column2=5;
Therefore, it is safe to convert the query to a normal join:
SELECT * FROM tableA, tableB WHERE tableB.column2=5 AND tableA.column1=tableB.column1;
SELECT * FROM tableA LEFT JOIN tableB ON (column1) WHERE tableB.column2=5;
Therefore, it is safe to convert the query to a normal join:
SELECT * FROM tableA, tableB WHERE tableB.column2=5 AND tableA.column1=tableB.column1;
Friday, October 30, 2009
Group by in custom query in drupal
We should Keep in mind the followings when we use group by in custom queries.
ex: SELECT pname, MIN(price) FROM products GROUP BY pname;
1. The column that you GROUP BY must also be in your SELECT statement.
2. Remember to group by the column you want information about and not the one you are applying the aggregate function on. In our above example we wanted information on the pname and the aggregate function was applied to the price column.
ex: SELECT pname, MIN(price) FROM products GROUP BY pname;
1. The column that you GROUP BY must also be in your SELECT statement.
2. Remember to group by the column you want information about and not the one you are applying the aggregate function on. In our above example we wanted information on the pname and the aggregate function was applied to the price column.
More Mysql Indexes affect performance on heavy traffic site
I want to share about index on table columns. Indexes are something extra that you can enable on your MySQL tables to increase performance, but they do have some downsides. When you create a new index MySQL builds a separate block of information that needs to be updated every time there are changes made to the table. This means that if you are constantly updating, inserting and removing entries in your table this could have a negative impact on performance. So avoid using index unnecessarily. That will affect the performance.
Subscribe to:
Posts (Atom)