[PHP] Little Info...

2012-02-29 Thread Don Wieland
This is a bit related to PHP but mostly mySQL (is there a similar list  
for this stuff? Let me know please)


In my mySQL query editor, I am trying to return a value of 0 when  
there is no related rows from this query:


(select if(count(ip.payment_amount) IS NOT NULL,  
count(ip.payment_amount) , 0)  FROM tl_trans_pmt_items ip WHERE  
t.transaction_id = ip.inv_id GROUP BY ip.inv_id) as d,


regardless of the combination I use, invalid relationships come back  
as NULL - need to return 0  so I can use it in a math formula.


Probably simple - maybe ;-)

Thanks,

Don

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Little Info...

2012-02-29 Thread Daniel Brown
On Wed, Feb 29, 2012 at 13:01, Don Wieland d...@pointmade.net wrote:
 This is a bit related to PHP but mostly mySQL (is there a similar list for
 this stuff? Let me know please)

php...@lists.php.net and p...@lists.mysql.com, specifically.

-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Little Info...

2012-02-29 Thread Matijn Woudt
On Wed, Feb 29, 2012 at 7:01 PM, Don Wieland d...@pointmade.net wrote:
 This is a bit related to PHP but mostly mySQL (is there a similar list for
 this stuff? Let me know please)

 In my mySQL query editor, I am trying to return a value of 0 when there is
 no related rows from this query:

 (select if(count(ip.payment_amount) IS NOT NULL, count(ip.payment_amount) ,
 0)  FROM tl_trans_pmt_items ip WHERE t.transaction_id = ip.inv_id GROUP BY
 ip.inv_id) as d,

 regardless of the combination I use, invalid relationships come back as NULL
 - need to return 0  so I can use it in a math formula.

 Probably simple - maybe ;-)

 Thanks,

 Don

While Daniel is right, you can use COALESCE for this. eg. select
COALESCE(count(ip.payment_amount), 0)

- Matijn

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Little Info...

2012-02-29 Thread Ashley Sheridan
On Wed, 2012-02-29 at 19:27 +0100, Matijn Woudt wrote:

 On Wed, Feb 29, 2012 at 7:01 PM, Don Wieland d...@pointmade.net wrote:
  This is a bit related to PHP but mostly mySQL (is there a similar list for
  this stuff? Let me know please)
 
  In my mySQL query editor, I am trying to return a value of 0 when there is
  no related rows from this query:
 
  (select if(count(ip.payment_amount) IS NOT NULL, count(ip.payment_amount) ,
  0)  FROM tl_trans_pmt_items ip WHERE t.transaction_id = ip.inv_id GROUP BY
  ip.inv_id) as d,
 
  regardless of the combination I use, invalid relationships come back as NULL
  - need to return 0  so I can use it in a math formula.
 
  Probably simple - maybe ;-)
 
  Thanks,
 
  Don
 
 While Daniel is right, you can use COALESCE for this. eg. select
 COALESCE(count(ip.payment_amount), 0)
 
 - Matijn
 


What's wrong with checking the number of rows returned in PHP? If the
number of rows is 0, you have no results. If the number is 1, then use
the SQL results value.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk