Empty seems to be different from isset? See the following code for solutions

Source: Internet
Author: User
Empty seems to be different from isset? See the following code & lt; html & gt; & lt; head & gt; & lt; metahttp-equiv & quot; content-type & quot; content & quot; texthtml; charsetutf-8 & quot; & gt; & lt; head & gt; & lt ;? What is the difference between php & nbsp; empty and isset? See the following code





// Display information of all users (table)
// Query data
$ Conn = mysql_connect ("localhost", "root", "5200") or die (mysql_error ());

// Sets the mysql encoding.

Mysql_query ("set names UTF-8", $ conn );
// Select a database

Mysql_select_db ("manage", $ conn) or die (mysql_error ());

$ PageSize = 3; // number of records per page
$ RowCount = 0;

If (! Empty ($ _ GET ['pagenow']) {
$ PageNow = 1;
}
Else {
$ PageNow = $ _ GET ['pagenow'];
}

$ SQL = "select count (id) from emp ";
$ Res1 = mysql_query ($ SQL );
If ($ row = mysql_fetch_row ($ res1 )){
$ RowCount = $ row [0]; // rowCount indicates the number of data records.
}
// Calculate the number of pages
$ PageCount = ceil ($ rowCount/$ pageSize );
$ SQL = "select * from emp limit". ($ pageNow-1) * $ pageSize. ", $ pageSize ";

$ Res2 = mysql_query ($ SQL, $ conn );
// $ SQL = "select * from emp ";


Echo "employee information table ";
Echo"







";Echo" ";While ($ row = mysql_fetch_assoc ($ res2 )){Echo" "." "." ";}Echo"
Id Name Grade Email Slary Modify user Delete a user
{$ Row ['id']} {$ Row ['name']} {$ Row ['grade ']}{$ Row ['email ']} {$ Row ['salary ']}Delete a user Modify user
";
// Print the page number hyperlink
For ($ I = 1; $ I <= $ pageCount; $ I ++)
{
Echo "$ I ";
}

?>





------ Solution --------------------
My friends often repeat

Bool empty (mixed $ var)

If var is a non-null or non-zero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, array (), var $ var; and objects without any attributes will be considered empty, if var is null, TRUE is returned.


Bool isset (mixed $ var [, mixed $ var [, $...])

If var exists, TRUE is returned; otherwise, FALSE is returned.

If unset () is used to release a variable, it will no longer be isset (). If you use isset () to test a variable that is set to NULL, FALSE is returned. Note that a NULL byte ("\ 0") is not equivalent to the NULL constant of PHP.
------ Solution --------------------
PHP code
$ Str = 0; var_dump (empty ($ str); // truevar_dump (isset ($ str); // true
------ Solution --------------------
! Empty ($ x) = isset ($ x) & $ x
Empty ($ x) =! Isset ($ x) |! $ X

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.