Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread CPT John W. Holmes
From: "Chris Boget" <[EMAIL PROTECTED]> > > From: "Chris Boget" <[EMAIL PROTECTED]> > > > My bad. > > > If MySQL had crosstab functionality, that *might* be able to help. > > A "crosstab" is just a specifically formatted query, of which MySQL is > > certainly capable of handling. I've done them in

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread CPT John W. Holmes
From: "David T-G" <[EMAIL PROTECTED]> > [Actually, maybe I'm just too new at this, but I > can't think of a practical example for which I would loop over $row... > Care to help me out?] How about a dynamic query where you do not know the number of columns that'll be returned? You would not want t

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Chris Boget
> From: "Chris Boget" <[EMAIL PROTECTED]> > > My bad. > > If MySQL had crosstab functionality, that *might* be able to help. > A "crosstab" is just a specifically formatted query, of which MySQL is > certainly capable of handling. I've done them in the past, but maybe you're > thinking of something

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread David T-G
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jon, et al -- ...and then Jon Kriek said... % % Perhaps if you would stop sending your posts at attachments ;) Oh, that. I blame your mail mangler still, but this message has been folded, spindled, and mutilated just for you :-) HAND :-D - -- D

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread David T-G
Chris, et al -- ...and then Chris Boget said... % ... % > than maybe making my script run a little more slowly, I fail to see how % > mysql_fetch_array() is a bad thing. From what I can see, all it does is give % > me an additional numerically indexed reference to the data in my result set ... %

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread CPT John W. Holmes
From: "Chris Boget" <[EMAIL PROTECTED]> > My bad. > If MySQL had crosstab functionality, that *might* be able to help. A "crosstab" is just a specifically formatted query, of which MySQL is certainly capable of handling. I've done them in the past, but maybe you're thinking of something more compl

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Jon Kriek
Perhaps if you would stop sending your posts at attachments ;) >> Dude, your quoting *really* needs some help -- Jon Kriek http://phpfreaks.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread David T-G
Devon -- ...and then Devon said... % % David T-G wrote: % % >Note that I don't recommend this as the best approach, and I don't think ... % >doing it in two steps of loading your $everyone and then spitting out I'd % >probably do something like % > % > $sql = "select id,name from a_table order

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread David T-G
Chris, et al -- ...and then Chris Boget said... % % > % Actually, mysql_fetch_assoc() will do quite nicely. % > Really? How? I must be quite confused. % % No, actually, I am the one who's confused. I misread the OP's email such % that *_assoc() would do the job. *whew* Glad to hear that --

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread David T-G
Jon, et al -- ...and then Jon Kriek said... % % Trust me, I was not "shooting anyone down", I would rather quit programming % then do that - seriously. Fair enough, and truce declared. Now to simply discuss the finer points of mysql_fetch_* :-) % % -- % Jon Kriek % http://phpfreaks.com HA

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Devon
David T-G wrote: Note that I don't recommend this as the best approach, and I don't think that anyone else does, either. Usually you want to avoid sucking an entire database into your script's memory; the database (and its coders) almost always handles data better than we mere mortals. A much be

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread David T-G
Jon -- ...and then Jon Kriek said... % % Easier is not always "right" or "good script-logic" Admitted. I just want to know why it's wrong or so-very-not-good. % % Would it be easier for you to type: % % mysql_fetch_array($result, MYSQL_ASSOC) { If I needed to care about the space used by a

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Devon
Cpt John W. Holmes wrote: while($r = mysql_fetch_assoc($result)) { $array[$r['id']] = $r['name']; } ---John Holmes... Wonderful! Thats exactly what I was looking for! I ended up taking the array out of the equation entirly as suggested by Davic T-G, but the simplicity of your answer was exactly

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Jon Kriek
30% increase is more than I was expecting, but nonetheless I was correct. -- Jon Kriek http://phpfreaks.com "Peter Beckman" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Mysql_fetch_assoc() is faster -- use it. -- PHP Database Mailing List (http://www.php.net/) To unsubscri

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Chris Boget
> result set. Chris, you've made a believer out of me; I'll start using > mysql_fetch_assoc() for these kinds of queries from now on. :p > And in the spirit of only retrieving what you need from the database, I > would agree that mysql_fetch_assoc() is the "better" option. However, other > than

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Ignatius Reilly
OTECTED]> Sent: Monday, October 20, 2003 4:13 PM Subject: Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays > That is your personal opinion to which you are entitled to, but again > "shooting someone down" is just not the case in this situation. > >

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Peter Beckman
On Mon, 20 Oct 2003, Jon Kriek wrote: > Easier is not always "right" or "good script-logic" > > Would it be easier for you to type: > > mysql_fetch_array($result, MYSQL_ASSOC) { OK, can we clear this up once and for all? mysql_fetch_assoc(): 3.7182140350342 seconds [18880 rows] mysql_fetch_

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Jon Kriek
That is your personal opinion to which you are entitled to, but again "shooting someone down" is just not the case in this situation. >> No, but IMNSHO he shot a rather rude hole in Ignatius. "David T-G" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] -- PHP Database Mailing List (

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Chris Boget
> % > The original poster actually mentioned an associative array with one > % > field as the index and another as the value. None of these, just > % > Ignatius's suggestion, will do the job. > % Actually, mysql_fetch_assoc() will do quite nicely. > Really? How? I must be quite confused. No,

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Jon Kriek
Trust me, I was not "shooting anyone down", I would rather quit programming then do that - seriously. -- Jon Kriek http://phpfreaks.com "David T-G" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread David T-G
Chris -- ...and then Chris Boget said... % % > The original poster actually mentioned an associative array with one db % > field as the index and another as the value. None of these, just like % > Ignatius's suggestion, will do the job. % % Actually, mysql_fetch_assoc() will do quite nicely.

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Devon
Chris Boget wrote: The original poster actually mentioned an associative array with one db field as the index and another as the value. None of these, just like Ignatius's suggestion, will do the job. Actually, mysql_fetch_assoc() will do quite nicely. Im afraid not. I already tried that. It u

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Jon Kriek
Easier is not always "right" or "good script-logic" Would it be easier for you to type: mysql_fetch_array($result, MYSQL_ASSOC) { >> It's easier for me to just always use mysql_fetch_array instead of figuring out whether I want mysql_fetch_row, mysql_fetch_assoc, or both. "David T-G" <[EMAIL PRO

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread David T-G
Chris, et al -- ...and then Chris Boget said... % % Actually, for an associative array (which the OP had made reference % to), you use mysql_fetch_assoc(). See my response to Jon. No single function of which I know is going to pull what he requested out of the database in the format he desires.

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Chris Boget
> The original poster actually mentioned an associative array with one db > field as the index and another as the value. None of these, just like > Ignatius's suggestion, will do the job. Actually, mysql_fetch_assoc() will do quite nicely. > I didn't think it worth shooting down someone who wa

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Jon Kriek
gt; > Sent: Monday, October 20, 2003 9:42 AM > > To: Ignatius Reilly; [EMAIL PROTECTED]; Devon > > Subject: Re: [PHP-DB] Using two colomns of mysql data as > > key/value pairs > > in arrays > > > > > > > mysql_fetch_array( $result ) > > > &

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Chris Boget
> Curious as to why you say you avoid mysql_fetch_array() like the plague. I > use it frequently and am wondering if there is something wrong/not secure > when using it or if there is a huge amount of overhead associated with its > use. It's not that it's not secure, just that it's bad to use any

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread David T-G
Jon, et al -- ...and then Jon Kriek said... % % Ignatius, the original poster mentioned "an associative array" - The [snip] The original poster actually mentioned an associative array with one db field as the index and another as the value. None of these, just like Ignatius's suggestion, will d

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread David T-G
Devon -- ...and then Devon said... % ... % SELECT id, name FROM a_table; % % I just cannot figure out how to get that data from the resource handle % into an associative array with the 'id' colomn making up the keys and % the 'name' colomn making up the values. You won't get that directly;

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Jon Kriek
Chris, we think along the same lines - posted a similar concern seconds before you. -- Jon Kriek http://phpfreaks.com "Chris Boget" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > mysql_fetch_array( $result ) > > Actually, for an associative array (which the OP had made refere

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Chris Boget
> mysql_fetch_array( $result ) Actually, for an associative array (which the OP had made reference to), you use mysql_fetch_assoc(). I avoid mysql_fetch_array() like the plague unless there is a very specific need. Chris -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Jon Kriek
Ignatius, the original poster mentioned "an associative array" - The mysql_fetch_assoc() function fetches an associative array. If you want only that, use that function, if you want indices, use the mysql_fetch_row() function. If for some reason you need both, then you should use the mysql_fetch_ar

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread jeffrey_n_Dyke
$qry = "SELECT id, name FROM a_table"; $result = mysql_query($qry) or die(mysql_error()); while ($rs = mysql_fetch_row($result)) { $myarray[$rs[0]] = $rs[1]; } is that waht you need? hth Jeff

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread CPT John W. Holmes
From: "Devon" <[EMAIL PROTECTED]> > I have been scouring the online documentation and experimenting for > hours trying to find a solution. I just can't do it. > > I have two colomns of data that I am retrieving from MySQL: > >SELECT id, name FROM a_table; > > I just cannot figure out how

Re: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays

2003-10-20 Thread Ignatius Reilly
mysql_fetch_array( $result ) _ - Original Message - From: "Devon" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, October 20, 2003 3:30 PM Subject: [PHP-DB] Using two colomns of mysql data as key/value pairs in arrays > I have been scouring the online do