Author Topic: [SOLVED] Simple UPDATE query  (Read 1132 times)

0 Members and 1 Guest are viewing this topic.

Offline completeamateurTopic starter

  • Enthusiast
  • Posts: 69
    • View Profile
[SOLVED] Simple UPDATE query
« on: November 30, 2008, 04:59:14 PM »
Hi guys,

I'm trying to create a simple query to update some records.

Code: [Select]
$this->update(array('lft'=>'lft + 2'), 'lft > ' . $lft);
This works fine, except it does not write the correct value in the lft column, it just writes '0', where as it should be 'lft + 2' i.e. the original value + 2.  I'm not quite sure what I'm doing wrong.

TIA

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,228
    • View Profile
Re: Simple UPDATE query
« Reply #1 on: November 30, 2008, 05:07:31 PM »
That code allone doesn't make much sense without context. You should at least inform us what framework / library your using.

Offline completeamateurTopic starter

  • Enthusiast
  • Posts: 69
    • View Profile
Re: Simple UPDATE query
« Reply #2 on: November 30, 2008, 05:10:03 PM »
Apologies, I'm using Zend Framework 1.5

Offline Daniel0

  • Administrator
  • 'Insane!'
  • *
  • Posts: 11,815
  • Gender: Male
  • ^bb|[^b]{2}$
    • View Profile
Re: Simple UPDATE query
« Reply #3 on: December 02, 2008, 07:15:16 AM »
Try $this->update(array('lft'=> new Zend_Db_Expr('lft + 2')), 'lft > ' $lft);

Which class does $this refer to here?

Offline completeamateurTopic starter

  • Enthusiast
  • Posts: 69
    • View Profile
Re: Simple UPDATE query
« Reply #4 on: December 02, 2008, 07:53:49 AM »
Daniel, that's worked a treat.  It was trying to enter it as a string rather than an expression.  Thank you so much.

Offline Daniel0

  • Administrator
  • 'Insane!'
  • *
  • Posts: 11,815
  • Gender: Male
  • ^bb|[^b]{2}$
    • View Profile
Re: Simple UPDATE query
« Reply #5 on: December 02, 2008, 08:11:20 AM »
No problem. Remember to click the "Topic Solved" button when you're done. I did it for you this time though :)