Alex J Sun Jan 22 18:57:54 -0500 2012

Subject: SQLBuilder problem please help!

This give me 2 errors:

Warning: Attempt to assign property of non-object in /home/alecapone/www/sort-order-code3.php on line 52

Fatal error: Call to a member function save() on a non-object in /home/alecapone/www/sort-order-code3.php on line 54

CODE BELOW:
first i $_GET these:
$position_up = $_GET['position_up'];
$positionactuelle_id = $_GET['positionactuelle_id'];
$positionactuelle = $_GET['positionactuelle'];

..then hell starts here below:( ...

$sqlsubject = new ActiveRecord\SQLBuilder('mysql://test:test@localhost/database', $table_name);
$sqlsubject->where("position = ?", $position_up); /* SELECT * FROM subjects WHERE position = $position_up */

$sqlsubject->get_where_values(); //i get the whole row SELECTED * with previous where postition ..sqlbuilder

$id = $sqlsubject->id; //get the ID of the selected row

$subjectrow = Subjects::find($id); // map the table subjects with ID selected

$subjectrow->position = $positionactuelle; //UPDATE that previously selected , position to $positionactuelle

$subjectrow->save(); //SAVE :) ...done updating first one.


Nanne Huiges Mon Jan 23 06:04:47 -0500 2012

The problems is as stated that there is no "save" method in the object $subjectrow.

There are several possibilities, and you'll just have to debug a bit to find out what it is.

1) var_dump($subjectrow) just after the find line (like so)

1 $subjectrow = Subjects::find($id); // map the table subjects with ID selected
2 var_dump($subjectrow);

2) Check out what that thing is. If it is 'false' you are not getting a subject with that ID (I think it should throw an exception, but not sure, there is a difference between find_by_xx and find, but I don't know what is what atm). If it is an object, check out what kind of object it is. An ActiverRecord Model should have a save(); method, but something else might not.

If you can't figure it out after that, then post the result of that var_dump here.

Alex J Mon Jan 23 09:55:51 -0500 2012

array(0) { }
...it returns NULL i think :( ... is this because this doesnt work:

//map database table : Subjects   ...this will create all variables
class Subjects extends ActiveRecord\Model {
static $table_name = 'subjects';
}
//sql : SELECT ALL ON subjects table
$sqlsubject = Subjects::find('all');

$sqlsubject = new ActiveRecord\SQLBuilder('mysql://test:test@localhost/database', $table_name);
$sqlsubject->where("position = ?", $position_up); /* SELECT * FROM subjects WHERE position = $position_up */

$sqlsubject->get_where_values(); //i get the whole row SELECTED * with previous where postition ..sqlbuilder

$id = $sqlsubject->id; //get the ID of the selected row
var_dump($id);

Alex J Mon Jan 23 10:36:18 -0500 2012

Trying other ways...it does not work :

$position_up = 2;
$conditions =array('conditions'=>array('position = ?', $position_up));
$rowdata = Subjects::all($conditions);
var_dump($rowdata->menu_name); //returns NULL ? why ?

if ($test = Subjects::find('first')) { echo $test->menu_name;} // returns Services so its True, it does work but i am unable to execute a query like where position = 2 ...any help is appreciated

Alex J Mon Jan 23 11:05:04 -0500 2012

Ok this work ...good news : Problem is solved for now !
$position_up = 2;
$rowdata = Subjects::find_by_position($position_up);
echo $rowdata->menu_name;


But i someone tell me why i cant do any SQL related queries ? like this : **this one does not work returns NULL

$position_up = 2;
$conditions =array('conditions'=>array('position = ?', $position_up));
$rowdata = Subjects::all($conditions);
var_dump($rowdata->menu_name); //returns NULL ? why ?

Alex J Mon Jan 23 15:17:56 -0500 2012

Ok it works, but it creates an Array. Not an object.

$position_up = 2;
$row = Subjects::find_by_sql("select * from `subjects` where `position`= $position_up ");
echo '$row[0]->menu_name = ' . $row[0]->menu_name; //works

// Works too ! ! ! it they both create an array ! Be careful, Be aware this is an array. not an object. You can't call ->Save(); commands that we use on Objects.

$conditions =array('conditions'=>array('position = ?', $position_up));
$rowdata = Subjects::all($conditions);
echo $rowdata[0]->menu_name; //works

For those like me who is in love with Objects, this works :
$position_up = 2;
$rowdata = Subjects::find_by_position($position_up);
$rowdata->position = $positionactuelle; //UPDATE that previously selected , Assign $positionactuelle
$rowdata->save(); //SAVE :) ...done updating first one.
unset($rowdata);

Thanks to all those who helped on this one and who replied.
:-) enjoy life is beautiful

(1-5/5)