php programming

Content

  1. How to create automatic counter of record number in MySQL table using PHP?
  2. How to delete all files in a folder?
  3. Is it possible in PHP to replace blocks if…else with another conditional operation?
  4. How to delete strings from a text file using the PHP language?

How to create automatic counter of record number in MySQL table using PHP?

For this, we’ll use the following function:

<?php

// The function is designed for obtainment of record number of the table 
function get_id($tbl_dt)
{   // Do descending sorting 
    $result = mysql_query("SELECT id FROM ".$tbl_dt." ORDER BY `id` DESC");   
    $myrow = mysql_fetch_array($result);
    $num_rows = mysql_num_rows($result);
    
    // if a number of records coincide with the last id, then...
    if ($num_rows==$myrow['id'])
    {  // ...take the first element  
      //in the sampling with the highest id value ,
     // by increasing this value by a unity 
       return $myrow['id'] + 1;
       } else { // Do ascending sorting, then...
        $res1=mysql_query("SELECT id FROM ".$tbl_dt." ORDER BY `id` ASC");
        $myrow1 = mysql_fetch_array($res1);
        $i = 1;
        do // ...look for "empty" id and add a record for this id
        {
            if ($i == $myrow1['id']) {
                $i++;
                continue;
            } else {
                return $i;
            }
        }
        while ($myrow1 = mysql_fetch_array($res1));
    }
}

?>

Read more

php programming

At the writing of:

<?php
	session_start();
?>

An error message appeared:

Warning: session_start() [function.session-start]:
Cannot send session cache limiter – headers already sent (output started at X:/home/localhost/www/phpbloguser/header.html:6) in X:/home/localhost/www/phpbloguser/blocks/global.inc.phpon line 110

In php.ini it is necessary to write directive output_buffering “On” (on default – Off), see php.ini. And it will be all right! To make it works it is necessary to restart your server.

This error may appear for other reasons as well:

It is necessary to check if there is a space, tab, hyphen before “<?”.

In addition, it is necessary to start a session before any text appear in the browser’s window. Because in this case session identifier is written down in cookie files. Cookies in their turn are always installed through headers sending. The error message says that headers have ALREADY been sent.

Therefore it is necessary to check if any text appears in the browser’s window before you start a session by means of session_start()?

Your php file must be saved in UTF 8 coding (without BOM). If it is with BOM, three symbols will be  typed at the beginning of the file and this results in this error.

Content

  1. Using what query in MySQL it is possible to display several maximum values?
  2. What does the error ‘Too many connections’ mean?
  3. How to provide access to MySQL Denwer from the local network?
  4. How to delete records from a table if their date is 10 days earlier than the current one?
  5. How to use queries with UPDATE MySQL command?
  6. How to output the data from the primary and subordinated table into one by means of UNION MySQL query?

Read more

After you have launched installation file Denwer3_Base_2008.exe, a dialogue window with a question will appear:

Confirm installation of Denwer (local server)

By pressing “yes”, in response you will get the following window:

Close brower to continue the installation of Denwer (local server)

Now we go to the browser where a page with the message will open saying that installation of Denwer is started. In order to continue the installation, it is necessary to close this window of the browser.

Installation of Denwer (local server)

Upon closing the browser, it is necessary to indicate in which folder we are going to install our local server. On default this is C:\WebServers. If you wish you may indicate another place as well.

Indicate the installation directory

Then it is necessary to indicate on which virtual disk our path will be C\:WebServers. For instance it is possible to indicate disk X.

Installation of virtual disk

Then it is necessary to indicate the option of load of virtual disk. Let’s choose the first option. After this, indicate that it is necessary to create shortcuts on the desktop, by printing Roman letter “y”.

Installation of virtual disk

Go to the desktop and start Denwer by pressing shortcut “Start Denwer”.

Installation of Denwer has been successfully completed

After starting Denwer, check its operability by pressing point 2 (it is underlined with the red) in the browser’s window. Browser’s window will open and we’ll see a message: “It works!”. We need to go down and find a table with references for Denwer testing :

Installation of Denwer has been successfully completed

We are interested in the reference underlined with the red. Using this reference, we’ll get information about PHP. In particular we need to know where php.ini file is located. In future this information will help us. By pressing the reference we’ll get a table where we are most interested in the following line:

Location of php.ini file
PHP Examples of the regular expressions

Content

  1. How to get a substring inside the brackets from the string?
  2. How to substitute a substring inside the brackets in a string taking the ending standing right after the closing bracket?
  3. How to get a value of variable from url using regular expression PHP?
  4. How to cut out text inside a tag?
  5. Exploding, cutting an src attribute of the img tag from the text
  6. Exploding, cutting an img tag from the text together with the attributes

Read more