TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 05-09-2009, 11:57 PM   #1 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default unusual behavior (database class)

I am getting an odd behavior with my database class. Here's what my fetch method looks like.


PHP Code:
public function fetch($fetch_type 'array') {
    
        
switch (
$fetch_type) {
        
case 
'array'
return 
mysql_fetch_array($this->results);
break;
            
case 
'assoc':
return 
mysql_fetch_assoc($this->results);
break;

case 
'object':
return 
mysql_fetch_object($this->results);
break;
}



In my main script. If I assign the object to a variable, I get the correct output. My table only has 1 record so I get this.


PHP Code:
$rows $db->fetch();
    
echo 
"Key: $rows[0] AND Value: $rows[1]"
My output is:

Key: 0 AND Value: Cleo


But if I do a foreach on the "$row" variable, I get a whole bunch of data...


PHP Code:
foreach ($rows AS $key => $value) {
    echo 
"Key: $key AND Value: $value <Br />";
    } 

My output is:

Quote:
Key: 0 AND Value: 0
Key: postalcode_id AND Value: 0
Key: 1 AND Value: cleo
Key: cat_name AND Value: cleo
Key: 2 AND Value: 90210
Key: postcode AND Value: 90210
Key: 3 AND Value: sold
Key: status AND Value: sold
Key: 4 AND Value:
Key: extra AND Value:

Shouldn't the output be just like the first output?
Just one row?


Key: 0 AND Value: Cleo ????

Also, the "mysql_num_rows" count comes back as 1, which is correct because there's only 1 record in the table..


ONE MORE THING....

I did a little troubleshooting...

When I do a count on "$rows":

$countme = count($rows);

I get back: 10


BUT, in my database class, I get just 1 back from this:


$count = $db->num_rows();

And the method looks like this:


PHP Code:
public function num_rows() {
    
return 
mysql_num_rows($this->results);
        

allworknoplay is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
base classes..... allworknoplay Absolute Beginners 16 05-10-2009 08:09 PM
A Generic Singleton Base Class Theo Advanced PHP Programming 7 08-18-2008 02:25 AM
[Tutorial] Basic tutorial about class basics Tanax Absolute Beginners 14 07-24-2008 01:37 PM
PHP5 Classes A to Z Part 1 quantumkangaroo Advanced PHP Programming 11 04-01-2008 04:21 AM
Tutorial: PHP and OOP, a beginners guide Village Idiot Tips & Tricks 0 09-06-2007 04:23 PM


All times are GMT. The time now is 10:37 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design