Zen Cart Logo
Forums / General Questions / php code for counting records (mysql_num_rows) -->

php code for counting records (mysql_num_rows) -->

Locked

Views: 2,648

Results 1 to 6 of 6
This thread is locked. New replies are disabled.
1 Feb 2008, 9:28 PM
#1
mac8mypc avatar

mac8mypc

New Zenner

Join Date:
Sep 2007
Posts:
14
Plugin Contributions:
0

php code for counting records (mysql_num_rows) -->

I'm coding a little admin mod and I'm having some trouble.. thought maybe a guru here could help.

I'm not that used to dealing with classes, but here's a simplified example of my code

$sql = "SOME SQL STATEMENT";
$get_list = $db->Execute($sql);
if($get_list->RecordCount() > 0) {
    while(!$get_list->EOF) {
        // do something
        $get_list->MoveNext();
    }
} else {
    echo "no records were found";
}

I get an error that RecordCount() is an undefined function... but I'm pretty sure that's the function in the query_factory.php file

Should I use another function to get the number of rows returned with my query?

2 Feb 2008, 12:31 AM
#2
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,850
Plugin Contributions:
3

Re: php code for counting records (mysql_num_rows) -->

can u post the exact error message as it appears in the browser ?

2 Feb 2008, 5:06 PM
#3
mac8mypc avatar

mac8mypc

New Zenner

Join Date:
Sep 2007
Posts:
14
Plugin Contributions:
0

Re: php code for counting records (mysql_num_rows) -->

Fatal error: Call to a member function on a non-object

The line it specifies has this code - if($get_list->RecordCount() > 0) {

2 Feb 2008, 5:24 PM
#4
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: php code for counting records (mysql_num_rows) -->

If you use $db inside a function, remember to declare it global.
Also, run that sql statement you have directly on phpmyadmin, see if it generates the result you expected.

2 Feb 2008, 6:24 PM
#5
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,850
Plugin Contributions:
3

Re: php code for counting records (mysql_num_rows) -->

on the page this is running on have you got an includes/require for application_top.php

4 Feb 2008, 5:02 PM
#6
mac8mypc avatar

mac8mypc

New Zenner

Join Date:
Sep 2007
Posts:
14
Plugin Contributions:
0

Re: php code for counting records (mysql_num_rows) -->

I found an error in my code. The example I posted works fine. But in coding my script, I missed something small and vitally important... always some stupid little thing.

Anyways, hopefully someone else who needs this question answered in the future can benefit from the post ;)

Thanks for the help all.