Press "Enter" to skip to content

Posts published in May 2006

SQL Sub Queries

A quick query structure to retrive the last row entry to a logging table, in this case there can be multiple rows that would return the same id and date but I want only the very last so this query works well.

[code]
$query=”SELECT a.user_id, a.access_date FROM superlog a
WHERE a.access_date = (SELECT MAX(b.access_date)
FROM superlog b
WHERE a.user_id=b.user_id)
AND ip = CONVERT( _utf8 ‘10.10.10.10’ USING latin1 )
COLLATE latin1_swedish_ci;
[/code]

MySQL DROP Command

The Drop command is used to delete all the records in a table using the table name as shown below:

Syntax:

$dropSQL=(“DROP tblName”);

Example

[code]
$dropSQL=(“DROP tblstudent”);
[/code]

MySQL UPDATE Command

The Update command is used to update the field values using conditions. This is done using ‘SET’ and the fieldnames to assign new values to them.

Syntax:

$updateSQL=(“UPDATE Tblname SET (fieldname1=value1,fieldname2=value2,…) WHERE fldstudid=IdNumber”);

Example:

[code]
$updateSQL=(“UPDATE Tblstudent SET (fldstudName=siva,fldstudmark=100) WHERE fldstudid=2”);
[/code]

MySQL INSERT Command

The Insert command is used to insert records into a table. The values are assigned to the field names as shown below:

Syntax:

$insertSQL=(“INSERT INTO tblname(fieldname1,fieldname2..) VALUES(value1,value2,…) “);

Example

[code]
$insertSQL=(“INSERT INTO Tblstudent(fldstudName,fldstudmark)VALUES(Baskar,75) “);
[/code]

MySQL DELETE Command

The Delete command is used to delete the records from a table using conditions as shown below:

Syntax:

$deleteSQL=(“DELETE * FROM tablename WHERE condition”);

Example:

[code]
$deleteSQL=(“DELETE * FROM tblstudent WHERE fldstudid=2”);
[/code]

MySQL SELECT Command

The Select command is used to select the records from a table using its field names. To select all the fields in a table, ‘*’ is used in the command. The result is assigned to a variable name as shown below:

Syntax:

$selectSQL=(“SELECT field_names FROM tablename”);

Example:

[code]
$selectSQL=(“SELECT * FROM tblstudent”);
[/code]

MySQL CREATE Command

CREATE Command

The Create command is used to create a table by specifying the tablename, fieldnames and constraints as shown below:

Syntax:

$createSQL=(“CREATE TABLE tblName”);

Example:

[code]

$createSQL=(“CREATE TABLE tblstudent(fldstudid int(10) NOTNULL AUTO_INCREMENT PRIMARY KEY,fldstudName VARCHAR(250) NOTNULL,fldstudentmark int(4) DEFAULT ‘0’ “);

[/code]

Disable right click with javascript

Though not able to stop anyone who really wants your source code, images, or other imbedded items, this will slow down some… disable right mouse click with a bit of JavaScript in your pages header

[code]



[/code]

php includes

php includes – rather than rewrite several lines of code for each page, for example adding a standardized header (or footer) to hundreds of pages, using a php include can save a lot of effort, especially when it comes time that you want to make universal changes across your site….. edit one file ie… header.php and every page calling for it’s header from this file is changed in single shot.

[code]

[/code]

There are as many uses for using includes as you can imagine, populating a set list of variables, database connection strings…