[PHP-DB] Re: mysqli_multi_query error tolerance
Thanks again for responding. I'd also welcome opinions from other members of this list... Chris writes: > Filipe Martins wrote: >> Thanks for responding, Chris. >> If I understand you right, you're saying that this is MySQL API >> issue, right? > > I assume it's handled by the database itself and not php. You could try a > different script (eg python, ruby, perl, whatever else can talk to mysql) > to see if that theory is correct. > >> But do you agree that mysqli_multi_query should at >> least accept a parameter to configure how to treat errors > > No, I don't agree with that. > > -- > Postgresql & php tutorials > http://www.designmagick.com/ > --- Send big files for free. Simple steps. No registration. Visit now http://www.nawelny.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Get ID of ROW when using aggregate functions
Hi, I have following table: id int(11) name varchar(255) company varchar(255) sallary int(11) CREATE TABLE `test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `company` varchar(255) NOT NULL, `sallary` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin2 AUTO_INCREMENT=1 ; With rows: INSERT INTO `test` (`id`, `name`, `company`, `sallary`) VALUES (1, 'Jane', 'Microsoft', 1), (2, 'Peter', 'Novell', 12000), (3, 'Steven', 'Microsoft', 17000); I want to select person from each company with a highest sallary. I run this SQL: SELECT id,name,company,MAX(sallary) FROM `test` GROUP BY company; And result is: id name company MAX( sallary ) 1 Jane Microsoft 17000 2 Peter Novell12000 Why it returned Jane (id 1) as a person with highest sallary (17000) when obviously Jane has sallary of 10 000? Thanks for any help. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Get ID of ROW when using aggregate functions
the answer is exactly what you asked for. It gave you the max salary per company and made a "lucky guess" (not really, alfabetically first) as to which name you wanted since you never specified this of the top of my head, try this. SELECT a.id,a.name,a.company,a.sallary FROM `test` a ,(select company,max(sallary) sallary from test group by company) b where a.company=b,company and a.sallary=b.sallary 2009/4/8 Ondrej Kulaty > Hi, > I have following table: > > id int(11) > name varchar(255) > company varchar(255) > sallary int(11) > > CREATE TABLE `test` ( > `id` int(11) NOT NULL AUTO_INCREMENT, > `name` varchar(255) NOT NULL, > `company` varchar(255) NOT NULL, > `sallary` int(11) NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=latin2 AUTO_INCREMENT=1 ; > > With rows: > > INSERT INTO `test` (`id`, `name`, `company`, `sallary`) VALUES > (1, 'Jane', 'Microsoft', 1), > (2, 'Peter', 'Novell', 12000), > (3, 'Steven', 'Microsoft', 17000); > > I want to select person from each company with a highest sallary. > I run this SQL: > > SELECT id,name,company,MAX(sallary) FROM `test` GROUP BY company; > > And result is: > > id name company MAX( sallary ) > 1 Jane Microsoft 17000 > 2 Peter Novell12000 > > Why it returned Jane (id 1) as a person with highest sallary (17000) when > obviously Jane has sallary of 10 000? > > Thanks for any help. > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Jack van Zanen - This e-mail and any attachments may contain confidential material for the sole use of the intended recipient. If you are not the intended recipient, please be aware that any disclosure, copying, distribution or use of this e-mail or any attachment is prohibited. If you have received this e-mail in error, please contact the sender and delete all copies. Thank you for your cooperation
Re: [PHP-DB] Get ID of ROW when using aggregate functions
there is probably a better way to achieve this, but, this is a quick solution mysql> SELECT * FROM test where sallary IN (SELECT MAX(SALLARY) FROM test GROUP BY company); +++---+-+ | id | name | company | sallary | +++---+-+ | 2 | Peter | Novell| 12000 | | 3 | Steven | Microsoft | 17000 | +++---+-+ 2 rows in set (0.00 sec) the answer to your question might lie by looking at this: mysql> SELECT * FROM `test` GROUP BY company; ++---+---+-+ | id | name | company | sallary | ++---+---+-+ | 1 | Jane | Microsoft | 1 | | 2 | Peter | Novell| 12000 | ++---+---+-+ 2 rows in set (0.00 sec) SQL experts here please enlighten us.. On Wed, Apr 8, 2009 at 6:54 PM, Ondrej Kulaty wrote: > Hi, > I have following table: > > id int(11) > name varchar(255) > company varchar(255) > sallary int(11) > > CREATE TABLE `test` ( > `id` int(11) NOT NULL AUTO_INCREMENT, > `name` varchar(255) NOT NULL, > `company` varchar(255) NOT NULL, > `sallary` int(11) NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=latin2 AUTO_INCREMENT=1 ; > > With rows: > > INSERT INTO `test` (`id`, `name`, `company`, `sallary`) VALUES > (1, 'Jane', 'Microsoft', 1), > (2, 'Peter', 'Novell', 12000), > (3, 'Steven', 'Microsoft', 17000); > > I want to select person from each company with a highest sallary. > I run this SQL: > > SELECT id,name,company,MAX(sallary) FROM `test` GROUP BY company; > > And result is: > > id name company MAX( sallary ) > 1 Jane Microsoft 17000 > 2 Peter Novell12000 > > Why it returned Jane (id 1) as a person with highest sallary (17000) when > obviously Jane has sallary of 10 000? > > Thanks for any help. > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
[PHP-DB] Fix your corrupted tables / ibdata1 problem
Dear everyone, I just love list and I think I should share this information on how to fix MySQL tables that are in use and according to the articles: http://articles.techrepublic.com.com/5100-10878_11-5193721.html and http://tgrove.com/2007/12/02/innodb-operating-system-error-number-13-in-a-file-operation/ - First you should goto the corrupt databse folder in "data"
[PHP-DB] Fix your corrupted tables / ibdata1 problem
Dear everyone, I just love list and I think I should share this information on how to fix MySQL tables that are in use and according to the articles: http://articles.techrepublic.com.com/5100-10878_11-5193721.html and http://tgrove.com/2007/12/02/innodb-operating-system-error-number-13-in-a-file-operation/ - First you should goto the corrupt databse folder in "data" - either fix all tables or if you know the table name: #> myisamchk -r *.MYI #> myisamchk -r /path/to/table.MYI - The, look for these lines, uncomment and change the paths innodb_data_home_dir = /usr/local/mysql/data/ innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = /var/db/mysql/ innodb_log_arch_dir = /usr/local/mysql/data/ - And now fix your permissions on the DATA directory. #>chown -R mysql:mysql /usr/local/mysql - or if u'd like more specific solution and when u get "error number 13" on starting up the Engine, then u must type this command: #> chown mysql:mysql /usr/local/mysql/ibdata1 And u're saved :)
[PHP-DB] Date formatting question
I need to reformat the output of the 'dates' field from '2009-04-08' to
'Wed. Apr. 8th'. Any help would be appreciated.
Thanks.
---
for ($counter = 0; $counter < mysql_num_rows($resultID); $counter++);
while ($row = mysql_fetch_object($resultID))
{
print "";
print "" . $row->dates . "";
print "" . $row->times . "";
print "" . $row->am_pm . "";
print "" . $row->height . "";
print "" . $row->cond . "";
print "";
}
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Date formatting question
Jack Lauman wrote:
I need to reformat the output of the 'dates' field from '2009-04-08' to
'Wed. Apr. 8th'. Any help would be appreciated.
You can either do it using mysql date formats (see
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format)
or something like date('...', strtotime($result->date));
See http://php.net/date and http://php.net/strtotime
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Date formatting question
See the date function
Http://www.php.net/date
Bastien
Sent from my iPod
On Apr 8, 2009, at 21:41, Jack Lauman wrote:
I need to reformat the output of the 'dates' field from '2009-04-08'
to 'Wed. Apr. 8th'. Any help would be appreciated.
Thanks.
---
for ($counter = 0; $counter < mysql_num_rows($resultID); $counter++);
while ($row = mysql_fetch_object($resultID))
{
print "";
print "" . $row->dates . "";
print "" . $row->times . "";
print "" . $row->am_pm . "";
print "" . $row->height . "";
print "" . $row->cond . "";
print "";
}
--
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
