Home > Backend Development > PHP Tutorial > Analysis of four query return results in PHP development_PHP tutorial

Analysis of four query return results in PHP development_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:32:56
Original
1019 people have browsed it

1.

Copy code The code is as follows:

$connection=mysql_connect("localhost","root","password"); //Connect and select the database server
mysql_select_db("test",$connection) ;
$query="insert into users(user_name)"; //Insert a piece of data in the test database
$query.="values('tuxiaohui')";
$result=mysql_query($ query);
if(!$query)
echo "insert data failed!
";
else{
$query="select * from users"; //Query data
$result=mysql_query($query,$connection);
for($rows_count=0;$rows_count<7;$rows_count++) //Use mysql_result to obtain data and output, mysql_result() returns a unit in the MySQL result set content.
{
echo "User ID:".mysql_result($result,$rows_count,"user_id")."
";
echo "User name:".mysql_result($result,$ rows_count,"user_name")."
";
}
}
?>

2.
Copy code The code is as follows:

$connection=mysql_connect("localhost","root","password"); //Connect and select the database server
mysql_select_db("test",$connection);
$ query="select * from users";
$result=mysql_query($query,$connection);
while($row=mysql_fetch_row($result))
{
echo "User ID: ".$row[0]."
";
echo "Username: ".$row[1]."
";
}
?>

3.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template