Welcome Guest, Not a member yet? Register   Sign In
$this->db->where
#1

[eluser]me_not_you[/eluser]
Hi,

I'm still getting started with CI...so sorry if my Q is dum...

but i've got 2 functions

Code:
function getone($id){
        
        $this->load->model('manifMod');
        $data['manif'] = $this->manifMod->getone($id);
        foreach ($data as $manifs):
            foreach ($manifs as $manif):
                $idorganisateur=$manif['idorganisateur_manif'];
                $idtype=$manif['idtype_manif'];
            endforeach;
        endforeach;
        $data['oraganisateur']=$this->getorganisateur($idorganisateur);
        $this->load->model('typesMod');
        $data['type'] = $this->typesMod->getname($idtype);
        $data['lastyear'] = $this->getlastyearsmanif($id);
        $this->load->view('manif',$data);
    }

function getlastyearsmanif($id){
        $this->load->model('manifMod');
        $idmanif=$this->manifMod->getlastyearsmanif($id);
        
        
            while (($idmanif<>'') or ($idmanif<>'0')):
                $this->load->model('manifMod');
                $data['manif'] = $this->manifMod->getone($idmanif);
                foreach ($data['manif'] as $manif):
                    $idmanif=$manif['idmanifprec_manif'];
                endforeach;
                echo($idmanif);
            endwhile;
        
        $this->load->view('comparer',$data);
    }

with 2 models

Code:
&lt;?php
//typesmod.php
public function getname($id){
        $types=$this->db->get('types',1);
        $this->db->where('IDtype', $id);
        foreach ($types->result() as $row)
        {
            $name=$row->nom_type;
        }
        return $name;
    }

//manifmod.php
?&gt;
and the where from typesmod.php comes back as
Code:
WHERE IDtype = 3 AND IDmanifestation = 1

How can i get the $this->db->where back to nothing??
#2

[eluser]TheFuzzy0ne[/eluser]
I can see four problems with your getname method.

1) You should ditch the closing ?&gt; PHP tag. It's not needed, and is not useful since it's the cause of a well known problem.

2) I'd strongly suggest adding underscores to your method name, and variables.

3) You are making your database query before setting the WHERE clause, which is why it's still there after you think you've made the first query.

4) You are not adding to the name array, you're only overwriting it with a string.

Here's my proposed replacement function for getname:

Code:
public function get_names($id){
    
    $this->db->where('IDtype', $id);
    $res = $this->db->get('types',1);
    $names = array();

    if ($res->num_rows() > 0)
    {
        $res = $res->result_array();

        foreach ($res->result() as $row)
        {
            $names[] = $row->nom_type;
        }
    }

    return $names;
}
#3

[eluser]me_not_you[/eluser]
thanks, that help me...

don't know why i left those php tags ;-)

just another thing i'm getting "marchÃ@" instead of marché

do you have any ideas??
#4

[eluser]TheFuzzy0ne[/eluser]
[url="http://validator.w3.org/"]Validate[/url] your HTML, and all will become clear. You'll no doubt need to set the page encoding, and add a doc type.
#5

[eluser]meigwilym[/eluser]
Quote:just another thing i’m getting “marchÃ@” instead of marché

Se ne marche pas? ;-)

You need to set the encoding for the files, any DataBase tables you may have and what's sent to the browser.

I save all files using UTF-8. Netbeans does this for me for every project now, but I used to do it in Notepad++ using the Format menu (encode in UTF-8).

All your DB table should be in utf8_general_ci collation (the tables and fields).

Finally, send a header before you output anything with
Code:
$this->output->set_header('Content-Type: text/html; charset=utf-8');
I set this in MY_Controller so that it's sent for every page. And include this line in your HTML:
Code:
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
This should be the first line after the &lt;head&gt; tag.

Bon chance!

Mei




Theme © iAndrew 2016 - Forum software by © MyBB