Ok I am trying the getNumRows();
I have my query which has this in the sql debug at the bottom of the page
WHERE `Post`.`id` = '34rfgn' AND `Post`.`rank` <= 2 AND `Post`.`status` = 0
with
Affected Num. rows Took (ms) beside the query
1 1 0
$post = $this->Post->getPostInfo($job_id, $this->Auth->user('id'), $rank);
$affected = $this->Post->getNumRows();
debug($affected); returns zero?
What am I doing wrong?
Is the getNumRows() set up right?
My test user can only view 1 Post. (that post os a 0 rank) I have 100 dummy
posts with different ranks and for testing purposes ths user has the highest
access lever so he should be able to see everything.
Post.rank can be 0,1, or 2 this User has rank of 2 so it should work. It
query has not changed as I ran my checkValid() but decided to go with the
getNumRows to eliminate the extra query.
Thanks,
Dave
-----Original Message-----
From: John Andersen [mailto:[email protected]]
Sent: October-16-09 3:43 AM
To: CakePHP
Subject: Re: Check Valid
That may be, but it seems to me that you then are performing two queries for
each need to retrieve a record, first to ask if there is any records, and
then to ask for the records! (Maybe I am wrong
here!!)
I think that querying for the records, checking for the number retrieved,
should be the optimal way :) Then always pass the number to the view, and
let the view show some message for the user to stop messing around :D or
some kinder message like "No information found".
Enjoy,
John
On Oct 16, 9:03 am, "Dave Maharaj :: WidePixels.com"
<[email protected]> wrote:
> There is another that I found.
>
> Model::hasAny
>
> Returns true if a record that meets given conditions exists.
>
> function hasAny($conditions = null) {
> return ($this->find('count', array('conditions' => $conditions,
'recursive'
> => -1)) != false);
>
> }
>
> Which I guess is pretty much the same as my validPost($id) except cleaner.
>
> public function validPost($id)
> {
> $valid = false;
> $params = array(
> 'contain' => false,
> 'conditions' => array(
> 'Post.id' => $id),
> 'fields' => array(
> 'Post.id'));
>
> $q = $this->find('first', $params);
>
> if (!empty($q)) {
> $valid = true;
> }
> return $valid;
> }
>
> Dave
>
> -----Original Message-----
> From: John Andersen [mailto:[email protected]]
> Sent: October-16-09 2:57 AM
> To: CakePHP
> Subject: Re: Check Valid
>
> I think you can use the models method getNumRows() which returns the
> number of rows returned in the last query!
> Enjoy,
> John
>
> On Oct 16, 12:19 am, "Dave Maharaj :: WidePixels.com"
> <[email protected]> wrote:
> > If you have posts 1, 2, and 3 for example and you type in view/4 and
> > there is no 4 the page still renders but it has no data. How can you
> > prevent this ?
>
> > I have
>
> > if ($this->Post->validPost($id) == true) {
>
> > which checks the DB for that id if found then do as normal
>
> > } else {
>
> > return them back to index
>
> > }
>
> > Is there an easier way to do that that i over looked?
>
> > Thanks,
>
> > Dave
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---