How to assign SQL query results to variables in php

藏色散人
Release: 2023-03-03 16:22:02
Original
3716 people have browsed it

php method to assign sql query results to variables: 1. Get a value through the "mysql_query($sql);" and "mysql_result($query,0);" methods; 2. Through "mysql_fetch_array" Get an array.

How to assign SQL query results to variables in php

Recommended: "PHP Video Tutorial"

Specific questions:

$sql = "select field1 from pre_common_member_profile where uid='$username'";
Copy after login

The result is like this:

field1 1234
Copy after login

How to assign 1234 to a variable

Solution:

You only take this one The value still needs to be an array. Just take one word.

$sql = "select field1 from pre_common_member_profile where uid='$username'"; $query = mysql_query($sql); $bianliang = mysql_result($query,0); echo $bianliang;
Copy after login

If you get an array.

$sql = "select field1 from pre_common_member_profile where uid='$username'"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { echo $row["field1 "]; }
Copy after login

The above is the detailed content of How to assign SQL query results to variables in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!