A simple automatic mail system (3)

Source: Internet
Author: User
A simple automatic mail system (III) & nbsp; php (as the mainstream development language) and MySQL (the best combination with PHP. How to extract data from MySQL (the best combination with PHP) databases. & Nbsp; well, we have a simple automatic email sending system (3)

Here we will introduce how php (as the mainstream development language) works with MySQL (the best combination with PHP. How to extract data from MySQL (the best combination with PHP) databases.

Well, we have successfully completed our requirements. a lot of data already exists in the database. The question now is, how can we query the data and get useful results?

In the following program, we will select "apple" user output.

--------------------------------------------------------



/* Declare some required variables */

$ Hostname = "yourhostname ";
$ Username = "yourusername ";
$ Password = "yourpassword ";
$ Userstable = "information";/* Data table access information created using MySQL (the best combination with PHP */
$ DbName = "yourdbname ";


/* Connect to the database */
MySQL (best combination with PHP) _ CONNECT ($ hostname, $ username, $ password) or die ("Unable to connect to database ");

@ MySQL (best combination with PHP) _ select_db ("$ dbName") or die ("Unable to select database ");


/* Select all "apple" users */

$ Query = "SELECT * FROM $ userstable WHERE (preference LIKE Apples )";

$ Result = MySQL (the best combination with PHP) _ QUERY ($ query );

/* Count the number of such users */

$ Number = MySQL (the best combination with PHP) _ NUMROWS ($ result );

/* Output result */

$ I = 0;

IF ($ number = 0 ):

PRINT"

Nobody in the database prefers Apples!

";

ELSEIF ($ number> 0 ):

PRINT"

Users preferring Apples: $ number

";

WHILE ($ I <$ number ):

$ Name = MySQL (the best combination with PHP) _ result ($ result, $ I, "name ");
$ Email = MySQL (the best combination with PHP) _ result ($ result, $ I, "email ");

PRINT "Visitor $ name likes Apples.
";
PRINT "Email address: $ email .";
PRINT"

";

$ I ++;

ENDWHILE;

PRINT"

";

ENDIF;


?>

--------------------------------------------------------

Save it as apples. php (as the mainstream development language) 3

Explanation: some newly used functions:

1. $ number = MySQL (the best combination with PHP) _ NUMROWS ($ result );

Syntax: int MySQL (the best combination with PHP) _ num_rows (string result );

· Result is returned from the array records returned by the _ query function MySQL (the best combination with PHP.
· Returns the number of rows that exist in $ result.

2. $ name = MySQL (the best combination with PHP) _ RESULT ($ result, $ I, "name ");

Syntax: int MySQL (the best combination with PHP) _ result (int result, int I, column );

This function will separate records and assign each record to the variable.
· $ Result indicates the array result in.
· $ I is the row of the index data.
· Column is the name of a column in a data table in MySQL (the best combination with PHP. You can also use variables.

Therefore, using a simple while loop, we can easily output data to the browser.

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.