MYSQL FOREIGN KEY

By Webdevelopmentlogics


To create mysql foreign key the table engine must be InnoDB and the version is 5.
CREATE TABLE `bookings` ( id INT , customer_id INT , FOREIGN KEY `customer_id` REFERENCES customer(id))ENGINE=INNODB;
ALTER TABLE `bookings` ADD CONSTRAINT FOREIGN KEY `customer_id` REFERENCES customer(id);

 

Highlight table row using Javascript

By Webdevelopmentlogics


if(document.getElementById(id).hasChildNodes()){
var ctds = document.getElementById(id).getElementsByTagName('TD');
for(var chld = 0; chld < ctds.length ;chld++ ){
ctds[chld].className ='selectedFromList';
}
}
if(document.getElementById(id).parentNode){
var ctrs = document.getElementById(id).parentNode.getElementsByTagName('TR');
for(var chld = 0; chld < ctrs.length ;chld++ ){
if(ctrs[chld].id != id){
var ctds = ctrs[chld].getElementsByTagName('TD');
for(var chltr = 0; chltr < ctds.length ;chltr++ )
ctds[chltr].className = 'noteSelectedNorm';
}
}
}

 


Use this css in the form tag

style=margin-bottom:0;

 


SELECT STR_TO_DATE( '$php_date', '%d-%m-%Y %H:%i:%S' )

 

Create object for php mailer class

By Webdevelopmentlogics


$sendmail = new PHPMailer();
$sendmail->From = 'user@domain';
$sendmail->FromName = 'Name';
$sendmail->AddReplyTo('user@domain', 'Name');
$sendmail->AddAddress('email');
$sendmail->WordWrap = 50;
$sendmail->IsHTML(true); // set email format to HTML
$sendmail->Subject = 'Mail Subject';
$sendmail->Body = 'Mail Message';
$message = "Added new Bets";
if($sendmail->Send()){
$message = "";
}

 


var oEditor = FCKeditorAPI.GetInstance('Body');
var oDOM = oEditor.EditorDocument;
var strFCKEditorText = "";
if (document.all)// If I.E.
{
strFCKEditorText = oDOM.body.innerText;
}
else
{
var r = oDOM.createRange();
r.selectNodeContents(oDOM.body);
strFCKEditorText = r.toString();
}

 


//start php tag
set_time_limit(0);
//end php tag
It has effect only if the safe mode is disabled in the server.

 


var child_window=window.open('','', 'toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=no,width=600,height=550,left = 507,top = 379');

child_window.document.write(document.form.parentwindowcontent);

 


shell_exec("/usr/local/bin/php -f index.php > index.html");

 


Yes.. The session works without cookies if the session.use_only_cookies is off in the php.ini. If the cookies is disabled in the Browser it passes the SESSIONID through the URL.

 


mysql -u user -p -h localhost data-base-name < data.sql

 


We can view the single procedure using the command SHOW CREATE PROCEDURE proc_name;
To delete the procedure - DROP PROCEDURE proc_name;
To view all the procedures - SHOW PROCEDURE STATUS;

 


We can change the field attribute by using ALTER AND CHANGE keywords.
Ex:

ALTER TABLE table_name CHANGE old_feild new_field datatype AUTO_INCREMENT;

 


We can change the size and font of TEXTAREA or any element using the id of the element
Ex:

textarea cols="20" rows="10" id="txtarea"
input name="button" value="ChangeFont" onclick="changeFont()" type="button"

function changeFont() {
document.getElementById('txtarea').style.fontWeight = 'bold';
document.getElementById('txtarea').style.fontFamily = 'arial';
document.getElementById('txtarea').style.fontStyle = 'italic';
document.getElementById('txtarea').style.fontSize = '14px';
document.getElementById('txtarea').style.color = 'red';
}

 

MYSQL STORED PROCEDURE

By Webdevelopmentlogics


By creating SP for application, we can create our logic seperate from the application. The main advantage for using this is we can reuse the code for differenct languages with ease.
Ex:
CREATE PROCEDURE `sp_user`(
id int,
name varchar(64),
type_id int,
OUT out_status varchar(10)
)
MODIFIES SQL DATA
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION,SQLWARNING,NOT FOUND
SET out_status = 'error';
IF id > 0 THEN
//Call the update query
ELSE
// Call the insert query
END IF;
SELECT out_status;
END;
You can call the procedures using the command : CALL `sp_user`(0,'user1','1',@out_status)

 


If you couldn't send mail from window server, please set the default confuguration for Windows in your code.
Ex:
ini_set("sendmail_from", "user_name@domain_name");
ini_set("SMTP","localhost");
ini_set("smtp_port","25");