// 按用户id
<?php
$user_id = 1;
$getall = mysql_query("SELECT name,username,email FROM users WHERE user_id = $user_id");
$row = mysql_fetch_assoc($getall);
$fullnameDB = $row['name'];
$emailDB = $row['email'];
$usernameDB = $row['username'];
?>
// 通过电子邮件和密码
<?php
$email = $_POST["email"];
$password = $_POST["password"];
$getall = mysql_query("SELECT name,username,email FROM users WHERE email = '$email' AND password = '$password'");
$row = mysql_fetch_assoc($getall);
$fullnameDB = $row['name'];
$emailDB = $row['email'];
$usernameDB = $row['username'];
?>
我会通过(codeigniter 模型有查询)来做到这一点:
$this->load->model("ModelName");
$query = $this->ModelName->functionNameInModel(params);
$result = $query->result();
if ($query->num_rows() > 0)
{
$row = $query->row();
$var = $row->table_column;
echo("var = " . $var);
} else {
// No records returned! HOLY ****! HUSTON WE GOT A PROBLEM!
// Handle it with some code here...
}