Home>Article>Backend Development> How to assign SQL query results to variables in php
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.
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!