Welcome Guest, Not a member yet? Register   Sign In
COUNT(*) returning 0 ?
#1

[eluser]dplgngr[/eluser]
I get a 0 when i tried to use COUNT to retrieve the number of data.

Code:
$query = $this->db->query('SELECT COUNT(*) AS total_count FROM `authorize_net` where `Transaction Status` = "Settled Successfully" and `Settlement Amount` = 9.95');
$row = $query->row_array();
echo $row['total_count'];

the result printed 0 whereas when i query it using the phpmyadmin it returned the right amount.

Can anybody help me with this asap?
Thanks!
#2

[eluser]sl3dg3hamm3r[/eluser]
And what do you get if you replace your query on behalf of testing with:

SELECT 'Test' AS total_count;

If you get 'Test' then it was definitely 0 returned by the DB...
#3

[eluser]dplgngr[/eluser]
[quote author="sl3dg3hamm3r" date="1256062264"]And what do you get if you replace your query on behalf of testing with:

SELECT 'Test' AS total_count;

If you get 'Test' then it was definitely 0 returned by the DB...[/quote]

I get this:
Code:
Error Number: 1054

Unknown column 'Test' in 'field list'

SELECT `Test` AS total_count;

And here is the phpmyadmin query result to clarify that the query should return a definite number.
#4

[eluser]sl3dg3hamm3r[/eluser]
Uh sorry, my fault, thought this syntax works with MySQL... can't remember the right syntax.
#5

[eluser]dplgngr[/eluser]
I tried it the other way:

Code:
$this->db->select('COUNT(*) AS total_count');
$this->db->from('authorize_net');
$this->db->where('`Transaction Status`="Settled Successfully" and `Settlement Amount`=9.95');
        
$query = $this->db->get();
$result = $query->result();
        
$this->total_count_dvd = $result;

But it returned an error:

Code:
A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Status`="Settled Successfully" and `Settlement Amount`=9.95' at line 3

SELECT COUNT(*) AS total_count FROM (`authorize_net`) WHERE `Transaction` Status`="Settled Successfully" and `Settlement Amount`=9.95
#6

[eluser]rogierb[/eluser]
Loose the double quotes.

Code:
$this->db->where("`Transaction Status`='Settled Successfully' and `Settlement Amount`=9.95");
#7

[eluser]dplgngr[/eluser]
[quote author="rogierb" date="1256064181"]Loose the double quotes.

Code:
$this->db->where("`Transaction Status`='Settled Successfully' and `Settlement Amount`=9.95");
[/quote]

Code:
$this->db->select('COUNT(*) AS total_count');
$this->db->from('authorize_net');
$this->db->where('`Transaction Status`="Settled Successfully" and `Settlement Amount`=9.95');
        
$query = $this->db->get();
$result = $query->result();
        
$this->total_count_dvd = $result;

I dont see any double quotes.
#8

[eluser]rogierb[/eluser]
around "Settled Successfully". Mysql does not support them.
#9

[eluser]dplgngr[/eluser]
[quote author="rogierb" date="1256065850"]around "Settled Successfully". Mysql does not support them.[/quote]

Code:
$this->db->where('`Transaction Status`="Settled Successfully" and `Settlement Amount`=9.95');

Can you suggest the exact code?

I tried this one:

Code:
$this->db->select('COUNT(*) AS total_count');
$this->db->from('authorize_net');
$this->db->where('`Transaction Status`=`Settled Successfully` and `Settlement Amount`=9.95');
        
$query = $this->db->get();
$result = $query->result();
        
$this->total_count_dvd = $result;

but it returned an error:

Code:
A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Status`=`Settled Successfully` and `Settlement Amount`=9.95' at line 3

SELECT COUNT(*) AS total_count FROM (`authorize_net`) WHERE `Transaction` Status`=`Settled Successfully` and `Settlement Amount`=9.95
#10

[eluser]codex[/eluser]
Try this:
Code:
$this->db->select('COUNT(*) AS total_count');
$this->db->from('authorize_net');
$this->db->where('Transaction Status', 'Settled Successfully');
$this->db->where('Settlement Amount', '9.95');
        
$query = $this->db->get();
$result = $query->result();
        
$this->total_count_dvd = $result;

But are your fields really called Transaction Status and Settlement Amount? That can't be right...




[quote author="dplgngr" date="1256067135"][quote author="rogierb" date="1256065850"]around "Settled Successfully". Mysql does not support them.[/quote]

Code:
$this->db->where('`Transaction Status`="Settled Successfully" and `Settlement Amount`=9.95');

Can you suggest the exact code?

I tried this one:

Code:
$this->db->select('COUNT(*) AS total_count');
$this->db->from('authorize_net');
$this->db->where('`Transaction Status`=`Settled Successfully` and `Settlement Amount`=9.95');
        
$query = $this->db->get();
$result = $query->result();
        
$this->total_count_dvd = $result;

but it returned an error:

Code:
A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Status`=`Settled Successfully` and `Settlement Amount`=9.95' at line 3

SELECT COUNT(*) AS total_count FROM (`authorize_net`) WHERE `Transaction` Status`=`Settled Successfully` and `Settlement Amount`=9.95
[/quote]




Theme © iAndrew 2016 - Forum software by © MyBB