PHP from zero single row (13) using PHP to display MySQL database data

Source: Internet
Author: User

1. Execute SQL statements in PHP

To get data from a database, first PHP executes a SQL statement that operates on a table, including a SELECT, INSERT, UPDATE, or DELETE statement. In general, executing a SELECT statement in PHP will find some record rows from the table. Execution of other statements will only return information about whether the statement executed successfully.

 
  Success ';
	$num =mysql_num_rows ($result);//Get the number of rows of the query's results
	Echo '
'. $num. ' Rows '; } Mysql_close ($conn); ? >
Typically, mysql_query () is also used with mysql_error () to find the cause of the problem, depending on the information generated by mysql_error () when there is a problem with the SQL statement execution.
 
  ERROR:". Mysql_error ()."


Problem:
. $sql "); if ($result) { echo ' Sqlsyntex: '. $sql. '
Success '; $num =mysql_num_rows ($result); Echo '
'. $num. ' Rows '; } Mysql_close ($conn); ? >
2. Processing the data result set in PHP

When an SQL statement is successfully executed in a program, you can use Mysql_fetch_array () to obtain a specific query result that uses this function to get the field value of the record.

 -->ERROR:". Mysql_error ()."


Problem:
. $sql "); if ($num =mysql_num_rows ($result)) {$row =mysql_fetch_array ($result); Echo '
';
	Print_r ($row);
Mysql_close ($conn);
? >
function mysql_fetch_array (), which tells you that the function returns a row in the result set, as an associative or normal array, and that the return array is both available by default. The array returned by Mysql_fetch_array () establishes two indexes for each field value: One is indexed numerically and the other is indexed by field names.
 ERROR: ". Mysql_error (). "
	


Problem:
. $sql "); if ($num =mysql_num_rows ($result)) {$row =mysql_fetch_array ($result); Echo '

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.