4 Replies - 240 Views - Last Post: 08 April 2014 - 04:49 AM Rate Topic: -----

#1 Lieoften  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 244
  • Joined: 06-January 10

Query only returning one record.

Posted 05 April 2014 - 05:52 PM

So... For whatever reason my website has decided to hate me today and just stopped working... About 4 hours ago, I had this code up and running perfectly. I was happy, gleeful almost, so i decided to go out for a bike ride before continuing my work.

I came back, started my server up and decided to continue working on the next function related to the one included further down this post. and what happened? well, the code decided to no longer function properly; instead of showing all acceptable "upgrades", the code now only shows the first one... i've even gone as far as too remove the requirements for selecting the upgrades... Instead to show every upgrade in the database... and still it's only showing one...

So i'm frustrated and pretty sure i'm going crazy... Does anybody have any input as to why this would stop working?

        $sql = "SELECT id, name, cost, count(*) FROM upgrades";
            	#WHERE id NOT IN (Select upgrade_id  FROM thehave8_site1.user_upgrades WHERE uid = :uid)
            	#AND nullif NOT IN(SELECT upgrade_id FROM thehave8_site1.user_upgrades WHERE uid = :uid2)
            	#AND prereq IN (SELECT upgrade_id FROM thehave8_site1.user_upgrades WHERE uid = :uid3);";
		$que = $this->db->prepare($sql);
		#$que->bindParam(':id', $id); //note the : before id
		#$que->bindParam(':id2', $id);
		#$que->bindParam(':uid', $this->uid);
		#$que->bindParam(':uid2', $this->uid);
		#$que->bindParam(':uid3', $this->uid);
		try { 
			$que->execute();
			while($row = $que->fetch(PDO::FETCH_BOTH))
			{
				echo $row[0];
			}
		} catch(PDOException $e) { echo $e->getMessage();}
	
		}


Is This A Good Question/Topic? 0
  • +

Replies To: Query only returning one record.

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3320
  • View blog
  • Posts: 11,227
  • Joined: 12-December 12

Re: Query only returning one record.

Posted 05 April 2014 - 05:56 PM

Quote

i've even gone as far as too remove the requirements for selecting the upgrades... Instead to show every upgrade in the database... and still it's only showing one...

Are all the upgrade records still in the database?
Was This Post Helpful? 0
  • +
  • -

#3 Lieoften  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 244
  • Joined: 06-January 10

Re: Query only returning one record.

Posted 05 April 2014 - 06:04 PM

There are currently 5 records in the database... I've figured out what was wrong with the code, for whatever reason the count(*) was preventing the records from being returned...

This post has been edited by Dormilich: 06 April 2014 - 12:32 AM

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3512
  • View blog
  • Posts: 10,136
  • Joined: 08-June 10

Re: Query only returning one record.

Posted 06 April 2014 - 12:36 AM

View PostLieoften, on 06 April 2014 - 02:04 AM, said:

for whatever reason the count(*) was preventing the records from being returned...

that’s what aggregate functions usually do, reduce a result set to a single value.
Was This Post Helpful? 0
  • +
  • -

#5 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 793
  • View blog
  • Posts: 1,679
  • Joined: 30-January 09

Re: Query only returning one record.

Posted 08 April 2014 - 04:49 AM

Your SQL isn't valid, if you use an aggregate clause like COUNT then you need to use the GROUP BY aggregating clause on your non-aggregated fields (I'd, name, cost)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1