Re: [PHP] DESC order results
Richard Lynch schreef: On Sun, January 13, 2008 12:54 pm, Danny Brow wrote: Just wondering if anyone could tell me how reliable the DESC order option is going to be when I am parsing thousands of records where they are multiple ChartNo's for the same clientNo. Or is there a better way to grab the most recent ChartNo. This is not actually a PHP question... Assuming ChartNo is some kind of autoincrement field, it HAPPENS to be 100% reliable in current MySQL implementation. Unfortunately, it's also 100% the *WRONG* way to go about this, as the MySQL dev team could change their implementation of autoincrement at any time, for any reason, and you'd be up the creek without a paddle [*]. If you want the most RECENT chart in time, you should time-stamp every chart with a datetime field, and use that in DESC in your query. You should take this discussion to the MySQL list if you wish to understand why. [*] It has just occured to me that being UP the creek with no paddle isn't much of a big deal, as you can just drift back down. Being DOWN the creek with no paddle, however, would be more problematic. English is such a curious language... I think it assumes that you want to be down (where shit creek meets fresh water) and, although the flow will take you there, shit flows so slowly that your stuck with a decision of straving to death waiting for the drift or using you hands as paddles ... but indeed curiouser and curiouser it is :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DESC order results
On Sun, January 13, 2008 12:54 pm, Danny Brow wrote: > Just wondering if anyone could tell me how reliable the DESC order > option is going to be when I am parsing thousands of records where > they > are multiple ChartNo's for the same clientNo. Or is there a better way > to grab the most recent ChartNo. This is not actually a PHP question... Assuming ChartNo is some kind of autoincrement field, it HAPPENS to be 100% reliable in current MySQL implementation. Unfortunately, it's also 100% the *WRONG* way to go about this, as the MySQL dev team could change their implementation of autoincrement at any time, for any reason, and you'd be up the creek without a paddle [*]. If you want the most RECENT chart in time, you should time-stamp every chart with a datetime field, and use that in DESC in your query. You should take this discussion to the MySQL list if you wish to understand why. [*] It has just occured to me that being UP the creek with no paddle isn't much of a big deal, as you can just drift back down. Being DOWN the creek with no paddle, however, would be more problematic. English is such a curious language... -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DESC order results
$query = 'SELECT * FROM eChart WHERE clientNo = "2" ORDER BY ChartNo DESC'; If you want just one record: $query = 'SELECT * FROM eChart WHERE clientNo = "2" ORDER BY ChartNo DESC LIMIT 0, 1'; BTW, you'd better ask the MySQL mlist: http://lists.mysql.com/ HTH, cheers Silvio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DESC order results
This is a MySQL question, not a PHP question. That said, what you want is the LIMIT keyword. On Sunday 13 January 2008, Danny Brow wrote: > Just wondering if anyone could tell me how reliable the DESC order > option is going to be when I am parsing thousands of records where they > are multiple ChartNo's for the same clientNo. Or is there a better way > to grab the most recent ChartNo. > > $link = mysql_connect('localhost', 'myuser', 'mypassword') or die('Could > not connect: ' . mysql()); > > mysql_select_db('mydatabase') or die('Could not select database'); > > $query = 'SELECT * FROM eChart WHERE clientNo = "2" ORDER BY ChartNo > DESC'; > > $result = mysql_query($query) or die('Query failed: ' . mysql_error()); > > $line = mysql_fetch_array($result, MYSQL_ASSOC); > > > // Just for testing > print mysql_num_rows($result); > > > > Thanks, > Dan > > > > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean. -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DESC order results
Thanks for the answer, didn't think of asking this in a MySQL forum, sorry. Dan On Sun, 2008-01-13 at 20:28 +0100, Jochem Maas wrote: > Danny Brow schreef: > > Just wondering if anyone could tell me how reliable the DESC order > > option is going to be when I am parsing thousands of records where they > > are multiple ChartNo's for the same clientNo. Or is there a better way > > to grab the most recent ChartNo. > > this is a mysql question not a php question, please try to ask questions > in the appropriate forum. > > the reliability of 'ORDER BY' is not tied to the ammount of > records returned. > > given that you only want the 'most recent' > (by which I assume you mean the 'highest value') ChartNo for > a given clientNo you should be performing a query that returns a > single row of data. > > also you shouldn't be quoting values pertaining to numeric fields > (I assume clientNo is an integer) > > 1. assuming ChartNo is numeric: > > SELECT MAX(ChartNo) as chartno FROM eChart WHERE clientNo=2 > > 2. assuming ChartNo is a varchar (or similar): > > SELECT ChartNo FROM eChart WHERE clientNo=2 ORDER BY ChartNo DESC LIMIT 0,1 > > > > > $link = mysql_connect('localhost', 'myuser', 'mypassword') or die('Could > > not connect: ' . mysql()); > > > > mysql_select_db('mydatabase') or die('Could not select database'); > > > > $query = 'SELECT * FROM eChart WHERE clientNo = "2" ORDER BY ChartNo > > DESC'; > > > > $result = mysql_query($query) or die('Query failed: ' . mysql_error()); > > > > $line = mysql_fetch_array($result, MYSQL_ASSOC); > > > > > > // Just for testing > > print mysql_num_rows($result); > > > > > > > > Thanks, > > Dan > > > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DESC order results
Danny Brow schreef: Just wondering if anyone could tell me how reliable the DESC order option is going to be when I am parsing thousands of records where they are multiple ChartNo's for the same clientNo. Or is there a better way to grab the most recent ChartNo. this is a mysql question not a php question, please try to ask questions in the appropriate forum. the reliability of 'ORDER BY' is not tied to the ammount of records returned. given that you only want the 'most recent' (by which I assume you mean the 'highest value') ChartNo for a given clientNo you should be performing a query that returns a single row of data. also you shouldn't be quoting values pertaining to numeric fields (I assume clientNo is an integer) 1. assuming ChartNo is numeric: SELECT MAX(ChartNo) as chartno FROM eChart WHERE clientNo=2 2. assuming ChartNo is a varchar (or similar): SELECT ChartNo FROM eChart WHERE clientNo=2 ORDER BY ChartNo DESC LIMIT 0,1 $link = mysql_connect('localhost', 'myuser', 'mypassword') or die('Could not connect: ' . mysql()); mysql_select_db('mydatabase') or die('Could not select database'); $query = 'SELECT * FROM eChart WHERE clientNo = "2" ORDER BY ChartNo DESC'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $line = mysql_fetch_array($result, MYSQL_ASSOC); // Just for testing print mysql_num_rows($result); Thanks, Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] DESC order results
Just wondering if anyone could tell me how reliable the DESC order option is going to be when I am parsing thousands of records where they are multiple ChartNo's for the same clientNo. Or is there a better way to grab the most recent ChartNo. $link = mysql_connect('localhost', 'myuser', 'mypassword') or die('Could not connect: ' . mysql()); mysql_select_db('mydatabase') or die('Could not select database'); $query = 'SELECT * FROM eChart WHERE clientNo = "2" ORDER BY ChartNo DESC'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $line = mysql_fetch_array($result, MYSQL_ASSOC); // Just for testing print mysql_num_rows($result); Thanks, Dan -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php