background preloader

Różne artykuły

Facebook Twitter

Mysql_insert_id. If you insert a data row by using the ON DUPLICATE KEY UPDATE clause in an INSERT-statement, the mysql_insert_id() function will return not the same results as if you directly use LAST_INSERT_ID() in MySQL.

mysql_insert_id

See the following example: <? // insert a datarow, primary key is auto_increment // value is a unique key $query = "INSERT INTO test (value) VALUES ('test')"; mysql_query( $query ); echo 'LAST_INSERT_ID: ', mysql_query( "SELECT LAST_INSERT_ID()" ), '<br>mysql_insert_id: ', mysql_insert_id(); This will print: LAST_INSERT_ID: 1mysql_insert_id: 1 In this case the function returns the same as the MySQL-Statement.But see the insert on an existing key:

PHP File Uploading. A PHP script can be used with a HTML form to allow users to upload files to the server.

PHP File Uploading

Initially files are uploaded into a temporary directory and then relocated to a target destination by a PHP script. Information in the phpinfo.php page describes the temporary directory that is used for file uploads as upload_tmp_dir and the maximum permitted size of files that can be uploaded is stated as upload_max_filesize. These parameters are set into PHP configuration file php.ini The process of uploading a file follows these steps − As usual when writing files it is necessary for both temporary and final locations to have permissions set that enable file writing. An uploaded file could be a text file or image file or any document.

Creating an upload form The following HTM code below creates an uploader form. <? It will produce the following result − Processing HTML checkbox forms with PHP. Form Processing with PHP. One of the best features of PHP is possibility to respond to user queries or data submitted from HTML forms.

Form Processing with PHP

You can process information gathered by an HTML form and use PHP code to make decisions based off this information to create dynamic web pages. In this tutorial we will show how to create an HTML form and process the data. The HTML Form Before you can process the information, you need to create an HTML form that will send information to your PHP script. There are two methods for sending data: POST and GET. Below is an HTML form that will send the data using the POST method.

The example HTML page above includes different form elements: input fields, select list, text area, radio buttons, checkboxes and a submit button. The Two Egg Problem. There are no tricks, gotchas or other devious ruses.

The Two Egg Problem

Don’t rat-hole with issues related to terminal velocity, potential energy or wind resistance. This is a math puzzle plain and simple. Think about the puzzle for a few minutes, and then read on. OK, let’s get back to the original two egg problem. As we’ve seen from above, the worst case using a binary search would break seven eggs; not acceptable when we only have two eggs. It does not take much imagination to see why a binary search solution will not work (optimally) for two eggs. This is certainly an improvement, but what is our worst case with this strategy? Thinking about the 10 floor strategy again we can see that, whilst our worst case is 19 drops, some other possible solutions will take less than this (for instance, if the first egg broke on floor 10 then, at worst, from here we only have to make nine more drops to find the solution).

Let’s break out some algebra. n + (n-1) + (n-2) + (n-3) + (n-4) + … + 1 >= 100. Why I wouldn’t use rails for a new company. We built Scribd into the #3 largest rails site by traffic and it worked for us, but these days I see a lot of new companies using rails and it feels like a mistake.

Why I wouldn’t use rails for a new company

I started using rails in 2006 right after DHH’s screencast which introduced rails to the world with a bang. We wrote the first version of Scribd in rails 0.7, when they hadn’t yet invented fancy things like migrations. At the time, rails had buzz but was far from a safe choice. Most new sites were still being written in PHP or Java, and there were huge numbers of engineers for those platforms. We were making a bet that rails would continue to gain mindshare, creating a deep set of open-source libraries and, most importantly, a pool of developers interested in working in it.

It was the right bet.