0

我有一张 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=array of one row ($_SESSION['id']

4

1 回答 1

1

我想你正在寻找result_array()

在此处查看手册

$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
}
于 2013-02-04T13:42:02.367 回答