0

I have one table korisnik with 3 columns (id, username, password). I want some like:

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

I want to do something like this in CodeIgniter (to get one row where id=array of one row ($_SESSION['id']

1 Answer 1

1

I think you are looking for result_array()

see the manual here

$query = $this->db->query("YOUR QUERY");

foreach ($query->result_array() as $row)
{
   echo $row['title'];
   echo $row['name'];
   echo $row['body'];
}

UPDATE

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
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes but I have two methost.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.