To generate a random number between 0 and 100 do this: srand((double)microtime()*1000000); echo rand(0,100);
How to insert javascript in php code
Just use PHP echo commands. <? echo “<script language=\”JavaScript\”>\n” ; echo “alert(” javascript from php “);\n” ; echo “</script>” ; ?>
How to get a user’s IP address using PHP
<? $domain = GetHostByName ( $REMOTE_ADDR ); ?>
How to count the number of occurences in a MySQL string
There is currently no built-in function to do this, so I use: SELECT LENGTH( ‘THIS TEST’ ) – LENGTH( REPLACE (‘THIS TEST’,’T’,”); Answer output is: 3
How to show records for Last Month, This Month, Last Week, This Week, Last Year, This Year in MySQL
Just add these AND SQL statements to your queries, in these examples the ORDER_DATE is your column name which holds the date you are comparing against. This Week AND YEARWEEK(ORDER_DATE) = YEARWEEK(CURRENT_DATE) Last Week AND YEARWEEK(ORDER_DATE) = YEARWEEK(CURRENT_DATE – INTERVAL
How to find all the duplicates in my MySQL table
SELECT <column name>, COUNT( <column name> ) AS numOcc FROM <table> GROUP BY <column name> HAVING ( COUNT( <column name>) >1 ) This is an example of where you have duplicates in one column only.
How to delete a primary key in MySQL
ALTER IGNORE TABLE <table> DROP PRIMARY KEY
How to add a primary key index to a table and ignore and remove duplicates
Use the following SQL statement, put more than one column name in the brackets if you want more than one column as the primary key. ALTER IGNORE TABLE ADD PRIMARY KEY ()
How to get the first word of a string using MySQL
There are two ways to do this using MID and LOCATE or by just using SUBSTRING_INDEX a. SELECT MID(,1,LOCATE(‘ ‘,)) FROM b. SELECT SUBSTRING_INDEX( , ‘ ‘, 1 ) FROM
How can I capitalise each word in a MySQL text string without using PHP
This function below will capitalise each word in the string, in the same way that UCWORDS works in PHP. Just copy this function code and run it at the Mysql command line prompt. DELIMITER $$ DROP FUNCTION IF EXISTS `ICap`$$
