Home>Article>Backend Development> How to assign SQL query results to variables in php

How to assign SQL query results to variables in php

藏色散人
藏色散人 Original
2020-08-01 09:15:23 3722browse

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'";

The result is like this:

field1 1234

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;

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 "]; }

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!

Statement:
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