我有一个表korisnik有3列(id,用户名,密码)。 我想要一些像:
$upit = "SELECT * FROM korisnik WHERE username = '" . $_POST['username'] . "'
AND password = SHA1('" . $_POST['password'] . "')";
$temp = $upit->fetch(PDO::FETCH_ASSOC);
$_SESSION['id'] = $temp['id'];
if ($pdo_izraz->num_rows() == 1) {
session_start();
$_SESSION['autorizovan'] = 1;
$temp = $pdo_izraz->fetch(PDO::FETCH_ASSOC);
$_SESSION['id'] = $temp['id'];
$upit = ("Select * from korisnici where id=" . $_SESSION['id']);*
$izraz = $dbh->query($upit);
$obj = $izraz->fetch(PDO::FETCH_ASSOC);
$username = $obj['username'];
echo "<p id='bbb'><b >$username</b>:Welcome</p>";
我想在CodeIgniter中执行类似的操作(获取一行,其中id =一行数组($ _SESSION ['id']
答案 0 :(得分:1)
我认为您正在寻找result_array()
请参阅手册here
$query = $this->db->query("YOUR QUERY");
foreach ($query->result_array() as $row)
{
echo $row['title'];
echo $row['name'];
echo $row['body'];
}
<强>更新强>
public function login($user, $pass) // Takeing the username/pass from form
{
$this->db->where('username', $user);
$this->db->where('password', md5($pass));
$query = $this->db->get('korisnici');
if ($query->num_rows() == 1)
{
$_SESSION['id'] = $this->query->row()->id;
return TRUE;
}
else
{
return FALSE;
}
}
public function getData()//Get result of array
{
$this->db->where('id', $_SESSION['id']);
$query = $this->db->get('korisnici');
return $query->result(); // here you can change for result_array() if you want
}