Data Abstraction Layer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
riley
Forum Commoner
Posts: 45
Joined: Thu May 02, 2002 6:31 pm

Data Abstraction Layer

Post by riley »

Yes I know there are many to choose from, and are better written but I am trying to create my own to learn. This code returns an multiple deminsion array with all the results but the last record always returns null values. I have created a identical one with mysql and everything works well. I am sure the last row has data (if I limit the results to 10, 9 have data if I limit the same code to 5, 4 have data). Obviously I am not showing all the functions, all are returning the correct data. I think it has todo with the for loop. Any thoughts.

Code: Select all

$this->qry = @mssql_query( $this->GetSql(), $this->GetConnId() );
	 
if ( $this->GetNumRows() > 0 ){
	for($i = 0; $i < $this->GetNumRows(); $i++)&#123;
		$this->result&#1111;$i] = mssql_fetch_assoc( $this->qry );
	 &#125;
return $this->result;
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Check your GetNumRows() function in that class. It could be that it returns "naturally" counted rows (starting with 1, 2, 3, etc.) while your array starts with 0,1,2,3 etc.

The for-next loop itself looks fine.
User avatar
riley
Forum Commoner
Posts: 45
Joined: Thu May 02, 2002 6:31 pm

Post by riley »

I believe you are right! As I take a detailed look at the return results it's the first line that is not being returned therefore the last line has no data.

The GetNumRows() returns an integer, value of 10 in this case.

Later that same evening...

Actually I was using ( mssql_fetch_assoc( $this->qry ); ) for testing earlier in the code and had forgotten to take it out. No eyes to see my owns mistakes.
Post Reply