martes, 30 de septiembre de 2014

Generate Random 10 Digit Number in PHP

Generate Random 10 Digit Number in PHP
PHP, Quick Tips 40 Comments

The application I’m developing requires a random 10 digit number as a bar code on season pass. A simple way to create a unique number is to use the following code:
?
1
  
$random = substr(number_format(time() * mt_rand(),0,'',''),0,10);

Here’s whats happening with the code:

The outer portion “substr” is used to chop down the random number we create to 10 characters. You will notice the number 10 at the end of the snippet, which can be changed to any number you want.

The “number_format” function helps get rid of the scientific notation that will arise from generating the random number. In the middle, “time()” and “mt_rand()” are multiplied. Time() is the number of seconds from January 1 1970, and rand() is a uniquely generated number through PHP.

Always remember that generating unique numbers is not fool proof.  If your application requires each number to be unique, perform a collision check in the database before saving.


- See more at: http://elementdesignllc.com/2011/06/generate-random-10-digit-number-in-php/#sthash.WrvYJJBc.dpuf

Generate Random 10 Digit Number in PHP

PHP, Quick Tips 40 Comments
The application I’m developing requires a random 10 digit number as a bar code on season pass. A simple way to create a unique number is to use the following code:
?
1
$random = substr(number_format(time() * mt_rand(),0,'',''),0,10);
Here’s whats happening with the code:
The outer portion “substr” is used to chop down the random number we create to 10 characters. You will notice the number 10 at the end of the snippet, which can be changed to any number you want.
The “number_format” function helps get rid of the scientific notation that will arise from generating the random number. In the middle, “time()” and “mt_rand()” are multiplied. Time() is the number of seconds from January 1 1970, and rand() is a uniquely generated number through PHP.
Always remember that generating unique numbers is not fool proof.  If your application requires each number to be unique, perform a collision check in the database before saving.
- See more at: http://elementdesignllc.com/2011/06/generate-random-10-digit-number-in-php/#sthash.WrvYJJBc.dpuf

Generate Random 10 Digit Number in PHP

PHP, Quick Tips 40 Comments
The application I’m developing requires a random 10 digit number as a bar code on season pass. A simple way to create a unique number is to use the following code:
?
1
$random = substr(number_format(time() * mt_rand(),0,'',''),0,10);
Here’s whats happening with the code:
The outer portion “substr” is used to chop down the random number we create to 10 characters. You will notice the number 10 at the end of the snippet, which can be changed to any number you want.
The “number_format” function helps get rid of the scientific notation that will arise from generating the random number. In the middle, “time()” and “mt_rand()” are multiplied. Time() is the number of seconds from January 1 1970, and rand() is a uniquely generated number through PHP.
Always remember that generating unique numbers is not fool proof.  If your application requires each number to be unique, perform a collision check in the database before saving.
- See more at: http://elementdesignllc.com/2011/06/generate-random-10-digit-number-in-php/#sthash.WrvYJJBc.dpuf

Generate Random 10 Digit Number in PHP

PHP, Quick Tips 40 Comments
The application I’m developing requires a random 10 digit number as a bar code on season pass. A simple way to create a unique number is to use the following code:
?
1
$random = substr(number_format(time() * mt_rand(),0,'',''),0,10);
Here’s whats happening with the code:
The outer portion “substr” is used to chop down the random number we create to 10 characters. You will notice the number 10 at the end of the snippet, which can be changed to any number you want.
The “number_format” function helps get rid of the scientific notation that will arise from generating the random number. In the middle, “time()” and “mt_rand()” are multiplied. Time() is the number of seconds from January 1 1970, and rand() is a uniquely generated number through PHP.
Always remember that generating unique numbers is not fool proof.  If your application requires each number to be unique, perform a collision check in the database before saving.
- See more at: http://elementdesignllc.com/2011/06/generate-random-10-digit-number-in-php/#sthash.WrvYJJBc.dpuf

Generate Random 10 Digit Number in PHP

PHP, Quick Tips 40 Comments
The application I’m developing requires a random 10 digit number as a bar code on season pass. A simple way to create a unique number is to use the following code:
?
1
$random = substr(number_format(time() * mt_rand(),0,'',''),0,10);
Here’s whats happening with the code:
The outer portion “substr” is used to chop down the random number we create to 10 characters. You will notice the number 10 at the end of the snippet, which can be changed to any number you want.
The “number_format” function helps get rid of the scientific notation that will arise from generating the random number. In the middle, “time()” and “mt_rand()” are multiplied. Time() is the number of seconds from January 1 1970, and rand() is a uniquely generated number through PHP.
Always remember that generating unique numbers is not fool proof.  If your application requires each number to be unique, perform a collision check in the database before saving.
- See more at: http://elementdesignllc.com/2011/06/generate-random-10-digit-number-in-php/#sthash.WrvYJJBc.dpuf

Generate Random 10 Digit Number in PHP

PHP, Quick Tips 40 Comments
The application I’m developing requires a random 10 digit number as a bar code on season pass. A simple way to create a unique number is to use the following code:
?
1
$random = substr(number_format(time() * mt_rand(),0,'',''),0,10);
Here’s whats happening with the code:
The outer portion “substr” is used to chop down the random number we create to 10 characters. You will notice the number 10 at the end of the snippet, which can be changed to any number you want.
The “number_format” function helps get rid of the scientific notation that will arise from generating the random number. In the middle, “time()” and “mt_rand()” are multiplied. Time() is the number of seconds from January 1 1970, and rand() is a uniquely generated number through PHP.
Always remember that generating unique numbers is not fool proof.  If your application requires each number to be unique, perform a collision check in the database before saving.
- See more at: http://elementdesignllc.com/2011/06/generate-random-10-digit-number-in-php/#sthash.WrvYJJBc.dpuf

Generate Random 10 Digit Number in PHP

PHP, Quick Tips 40 Comments
The application I’m developing requires a random 10 digit number as a bar code on season pass. A simple way to create a unique number is to use the following code:
?
1
$random = substr(number_format(time() * mt_rand(),0,'',''),0,10);
Here’s whats happening with the code:
The outer portion “substr” is used to chop down the random number we create to 10 characters. You will notice the number 10 at the end of the snippet, which can be changed to any number you want.
The “number_format” function helps get rid of the scientific notation that will arise from generating the random number. In the middle, “time()” and “mt_rand()” are multiplied. Time() is the number of seconds from January 1 1970, and rand() is a uniquely generated number through PHP.
Always remember that generating unique numbers is not fool proof.  If your application requires each number to be unique, perform a collision check in the database before saving.
- See more at: http://elementdesignllc.com/2011/06/generate-random-10-digit-number-in-php/#sthash.WrvYJJBc.dpuf

Foreign key MYSQL PHPMYADMIN

https://www.youtube.com/watch?v=J3xvwhqYYMQ
CASCADE
Whenever rows in the master (referenced) table are deleted (resp. updated), the respective rows of the child (referencing) table with a matching foreign key column will get deleted (resp. updated) as well. This is called a cascade delete (resp. update[2]).
RESTRICT
A value cannot be updated or deleted when a row exists in a foreign key table that references the value in the referenced table. Similarly, a row cannot be deleted as long as there is a reference to it from a foreign key table.
NO ACTION
NO ACTION and RESTRICT are very much alike. The main difference between NO ACTION and RESTRICT is that with NO ACTION the referential integrity check is done after trying to alter the table. RESTRICT does the check before trying to execute the UPDATE or DELETE statement. Both referential actions act the same if the referential integrity check fails: the UPDATE or DELETE statement will result in an error.
SET NULL
The foreign key values in the referencing row are set to NULL when the referenced row is updated or deleted. This is only possible if the respective columns in the referencing table are nullable. Due to the semantics of NULL, a referencing row with NULLs in the foreign key columns does not require a referenced row.
SET DEFAULT
Similar to SET NULL, the foreign key values in the referencing row are set to the column default when the referenced row is updated or deleted.

MYSQL JOINS

MySQL JOINs: An Introduction

This article is started with MySQL simple JOIN concept with PHP script. JOINs in database queries are used to retrieve data from more than one table using single query. On executing the join query, this will return a table in virtual manner which is not present  in database actually. For example, let there are two table in database namely tbl_links, tbl_categories and their structure is like as below format.
mysql_join
tbl_links
+----------+---------------+----------------+
| links_id | links_name    | links_category |
+----------+---------------+----------------+
| 1        | google.com    | 3              |
| 2        | phppot.com    | 1              |
| 3        | facebook.com  | 2              |
+-----------------+-------------------------+

tbl_tags
+--------+-------------------+
| tag_id | tag_name          |
+--------+-------------------+
| 1      | PHP               |
| 2      | Social Networking |
| 3      | Search Engine     |
| 4      | Java              |
+-----------------+----------+
The tbl_links table has links_category field as it’s foreign key where the primary key tag_id of tbl_tags will be stored here. Now we can create a table of data which is spread over these two tables, by comparing these two keys. For that, we are going to use MySQL JOINS as shown below.
$query = SELECT a.links_name, b.tag_name FROM tbl_links a, tbl_tags b WHERE a.links_category = b.tag_id
Before executing this query using PHP, we need to connect the database, about what we have discussed already in Access MySQL from PHP. This query will result a table to be displayed to the browser as follows.
tbl_links
+---------------+-------------------+
| links_name    | tag_name          |
+---------------+-------------------+
| google.com    | Search Engine     |
| phppot.com    | PHP               |
| facebook.com  | Social Networking |
+-----------------+-----------------+

Types of JOINs

There are several type of JOINs in MySQL. These are,
  • Inner JOIN – It is simple JOIN to to get common data between two tables as shown in this article.
  • Outer JOIN – It is also called as Full Outer JOIN, which will retrieve all the rows from both tables and represent NULL for the column index, if the condition of the JOIN is not satisfied.
  • Left JOIN – Retrieves all the rows from left table and display the data from other table if the condition is satisfied. Otherwise, it will display NULL.
  • Right JOIN – It is similar to Left JOIN, but works with respect to right table instead of left one.

Note:

MySQL JOINS can be applicable for SELECT, UPDATE and DELETE queries.
This MySQL tutorial was added on April 27, 2013.

http://phppot.com/php/mysql-joins-an-introduction/