OMG what is up with the documentation......

#1
[eluser]Neocrypter[/eluser]
Ok so this is the second time ive looked at the documentation use the example in there and its not doing what it says it dose.

example my current issue
Code:
$id=2;
  if (isset($id))
        {
            $query = $this->db->where('banned_user_id', $id);
            $query = $this->db->get('banned_users');
            return $query->row();
        }

that should produce SELECT * WHERE banned_user_id = '2' by my figuring, but what im getting is SELECT 2 WHERE banned_user_id = 2

and the example as take straight from the online docs
http://ellislab.com/codeigniter/user-gui...ecord.html
Code:
$this->db->where('name', $name);

// Produces: WHERE name = 'Joe'

Earlier in the doc i read that the db assumes * when when SELECT $X is not supplied

am I missing something or is the docs not accurate

#2
[eluser]Clooner[/eluser]
[quote author="Neocrypter" date="1281759675"]Ok so this is the second time ive looked at the documentation use the example in there and its not doing what it says it dose.

am I missing something or is the docs not accurate[/quote]

If you follow the manual it will exactly describe how to use AR correctly. Like so! Tongue
Code:
$this->db->where('banned_user_id', $id);
$query = $this->db->get('banned_users');
return $query->row();

#3
[eluser]Neocrypter[/eluser]
yup i tried that too exact same result as with what i have above, when i pasted that code it was me trying random things to try and sort it out.
Code:
$this->db->where('banned_user_id', $id);
            $query = $this->db->get('banned_users');
            return $query->row();

Quote:A Database Error Occurred
Error Number: 1054

Unknown column '2' in 'field list'

SELECT `2` FROM (`banned_users`) WHERE `banned_user_id` = '2'

#4
[eluser]Clooner[/eluser]
[quote author="Neocrypter" date="1281760524"]yup i tried that too exact same result as with what i have above, when i pasted that code it was me trying random things to try and sort it out.[/quote]

I didn't use AR for a while but AFAIK AR works really well for the basic stuff

What kind of db are you using, anything special? Did you retrieve the query generated by the profiler?

#5
[eluser]cahva[/eluser]
You must have have select somewhere there as that example works for other people Smile

#6
[eluser]Neocrypter[/eluser]
nope the db is nothing special at all, and as far as i can tell i dont have it anywhere as im directly calling the function in my model that uses's that code snipet im completely at a loss with what is going on

#7
[eluser]John_Betong[/eluser]
Try this:
Code:
$id = 2;
  $query = $this->db->get('banned_users');
           $this->db->where('banned_user_id', $id);

  echo $this->db->last_query();
  echo '<pre>';
    print_r($query->row());
  echo '</pre>';
  die;
&nbsp;

#8
[eluser]WanWizard[/eluser]
You can't put the where after the get, that doesn't work.

Can you do
Code:
var_dump($this->db->ar_select);
before your query, to make sure there are no selects defined somewhere?

#9
[eluser]Neocrypter[/eluser]
ok got passed that issues, its all working now, i went back through my code line by line and i did have a select statement in there, >.<, another quick question in my view i have a form im using the built in form helper im creating all the fields with arrays and form_X($y) which is pulling up the form and populating it correctly but when i go to submit its telling me that $y is an undefined variable why would it be doing that since $y is the array thats building the form which obviously working.

example
Code:
&lt;?php foreach($query as $row):
$banned_user_slname = $row['banned_user_id'];

$slname = array(
        'name'   => 'banned_user_slname',
        'id'   => 'banned_user_slname',
        'size'   => '50',
        'value' =>  $banned_user_slname,
        'readonly'=>'readonly'
     );
endforeach;?&gt;

&lt;?php
$hidden = array('banned_user_id'=>$this->uri->segment(3));
    echo form_open('banned_user/edit');
    echo '<p>'.form_label('Banned User').'<br />'.form_input($slname).'</p>';
        echo form_submit('mysubmit', 'Edit Banned User!');
?&gt;

clicking submit gives me this

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: slname

Filename: views/edit_banned_user_form.php

Line Number: 60


Also sorry im asking so many questions, but im on a major time crunch with this as in ive got to get it done tonight or my wife kids and I are going to get an eviction notice tomorrow... first paying job ive had In long time but i think its came a little too late.

#10
[eluser]pickupman[/eluser]
Code:
foreach($query->result() as $row){

}

Keep in mind that your foreach loop is only going to create one field. It will iterate each result and only save the string from the last iteration.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.