[PHP-DB] Handling database calculations with a php page
Hello, 3 tables hold money value but they are inputed into the database without the dollar symbol (without $). So the value could be 3.00 etc... I want to calculate by adding (+) them together. A username is in each table. So only the username matching in each table must calculate. So if in table 1 username Chris has 3.00 and in table 2 Chris has 5.00 we need to add the two together. If you value equals 0 or NULL or blank it should either a) ignore it or b) add it as a zero. What is the best PHP code to use for this inside a PHP code? Thanks! Find local movie times and trailers on Yahoo! Movies. http://au.movies.yahoo.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Handling database calculations with a php page
First of all, check the SELECT statement in your database documentation, because you do this within your select. It is important you that you inform yourself about this, because you will use it a lot. So this is not really a PHP question. The statement is written something like this: SELECT a.currency + b.currency + c. currency curr_total from a, b, c WHERE a.cust_id = b.cust_id AND b.cust_id = c.cust_id AND c.cust_id = '$customer_id'; (or cust_id and some kind of transaction identifier) ( Tables are named a, b and c for convenience. Those who prefer JOIN syntax would write it differently) Secondly, unless you are having problems with rounding errors or must preserve the state of an issued document, like an invoice or purchase order, why write to a 4th table? Your data is contained in a, b, and c, and queries are v. fast, so what advantage or benefit is derived from storing the results in d? If you must do it, then you use either an INSERT or UPDATE statement, with appropriate customer and transaction IDs to keep things straight. If you do not know how to use/write the PHP code to execute this, examine the mysql functions in the PHP docs and avail yourself of the numerous tutorials on the Web. Google for something like tutorial PHP MySQL. As much as possible, do the work within the database. Hope this is helpful. Regards - Miles At 07:38 AM 3/13/2005, JeRRy wrote: snip What is the best PHP code to use for this inside a PHP code? /snip I meant ... What is the best PHP code to use for this inside a PHP page/file. (e.g. calculate.php) Also the total of the 3 tables should than be updated to a 4th table which I did not mention. So the total of table 1, 2 and 3 should than be updated to a 4th table. I want to keep it all seperated like this (in different tables) so it's easier to manage and learn from. Thanks! Find local movie times and trailers on Yahoo! Movies. http://au.movies.yahoo.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Problems with 4.3.10 and SQL Server
I don't see many SQL Server posts here but I will give it a shot. I am using PHP 4.3.10, SQL Server 2000, and W2000. I have had no problems with scripting against PHP 5.x but I have had real problems when running these same scripts against 4.3.10. For example, all my select and insert statements do nothing. Submitting truncate commands against the database work, but a simple query like insert into input values('$lines') do nothing. Again, I have had no problems with 5.x. Any general suggestions or tricks to try. I have tried things such as fully quoting table names, bracketing the name, using 2 single quotes instead of 1. None of these suggestions work however. Jim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Problems with 4.3.10 and SQL Server
Does the mssql account user have the correct priviledges to be able to run those queries? Are you using proper error reporting to see if there are any error messages returned by mssql wrt those queries? (are you using http://ca3.php.net/manual/en/function.mssql-get-last-message.php to get the last message from the server)? bastien From: aifoundations.org [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] Problems with 4.3.10 and SQL Server Date: Sun, 13 Mar 2005 18:01:38 -0500 I don't see many SQL Server posts here but I will give it a shot. I am using PHP 4.3.10, SQL Server 2000, and W2000. I have had no problems with scripting against PHP 5.x but I have had real problems when running these same scripts against 4.3.10. For example, all my select and insert statements do nothing. Submitting truncate commands against the database work, but a simple query like insert into input values('$lines') do nothing. Again, I have had no problems with 5.x. Any general suggestions or tricks to try. I have tried things such as fully quoting table names, bracketing the name, using 2 single quotes instead of 1. None of these suggestions work however. Jim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Problems with 4.3.10 and SQL Server
- Original Message - From: Bastien Koert [EMAIL PROTECTED] Newsgroups: php.db To: [EMAIL PROTECTED]; php-db@lists.php.net Sent: Sunday, March 13, 2005 6:19 PM Subject: RE: [PHP-DB] Problems with 4.3.10 and SQL Server Does the mssql account user have the correct priviledges to be able to run those queries? Yes, everything I am trying to script has been confirmed to work against the database. Are you using proper error reporting to see if there are any error messages returned by mssql wrt those queries? (are you using http://ca3.php.net/manual/en/function.mssql-get-last-message.php to get the last message from the server)? Yes, I've tried it and I even directly queried @@ERROR. Nothing is diplayed using mssql_get_last_message, and @@ERROR displays 0. I suppose this must mean I am not connecting to the database. I wonder if there is ping command I could run to confirm I have proper access to the server. I am running this against the database of a host company so I'm not sure what the problem could be. phpinfo reports that SQL Server support exists. Oh vey, I just checked it again. I really screwed that one up. Apparently, there is no SQL Server support on the host server. I better work out this problem before worrying about 4.3.10 vs. 5.x differences. Thanks for your help. Jim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] PHP MSSQL bug
I have created a stored procedure wich is accessing an remote linked MSSQL 2000 server and works perfectly from Querry Analyzer. The problem occurs when I try to execute the stored procedure from php 5.0.3 (by using mssql_bind or mssql_query); I've got no error but no result either. It seems that php doesn't allows to access remote linked servers! -- Raul IONESCU -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php