Yii Framework Forum: Retrieving Record From Db - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Retrieving Record From Db Rate Topic: -----

#1 User is offline   jhouse153 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 10-January 13
  • Location:Salt Lake City, UT

Posted 22 January 2013 - 03:06 PM

I'm attempting to execute a query with the following format:


$criteria = new CDbCriteria;
$condition_string  = ' origin=\''.$input['origin'].'\'';
$condition_string  .= ' AND destination=\''.$input['dest'] .'\'';
$criteria->condition = $condition_string;

$pricing = Pricing::model()->with('pricing_routes')->findAll($criteria);


The query should retrieve two records from the database. If I enable logging, copy and paste the query Yii is executing into my db tool. The query retrieves two records, as it should.


The problem I'm having is:
count($pricing_records)
only yields one result. So obviously, when I'm trying to loop through the $pricing array, I'm not getting the appropriate results.

Any idea of what could be going on here? TIA.
0

#2 User is offline   Emile Bons 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 19-September 11
  • Location:Breda, The Netherlands

Posted 22 January 2013 - 03:12 PM

How is $pricing translated into $pricing_records? And why, if you only need the count, don't you use the COUNT() function of MySql?
0

#3 User is offline   jhouse153 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 10-January 13
  • Location:Salt Lake City, UT

Posted 22 January 2013 - 03:45 PM

My mistake. it should read:

count($pricing)


And I just used count() function to show that there was only one result in the array.

I could have just said:

foreach($pricing as $temp){echo 'here';}

and have it only display "here" once.

Thanks.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users