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 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 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.

 Any help would be wonderful! :)



 Using PHP 4.3.3 on Linux if it matters.

 --
 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] 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 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.

while($r = mysql_fetch_assoc($result))
{ $array[$r['id']] = $r['name']; }

---John Holmes...

-- 
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 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




   
 
  Devon
 
  [EMAIL PROTECTED]To:   [EMAIL PROTECTED]
   
  .netcc: 
 
   Subject:  [PHP-DB] Using two colomns of 
mysql data as key/value pairs in arrays  
  10/20/2003 09:30 
 
  AM   
 
   
 
   
 




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 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.

Any help would be wonderful! :)



Using PHP 4.3.3 on Linux if it matters.

--
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] 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_array() function; don't assign what you won't use.


-- 
Jon Kriek
http://phpfreaks.com

Ignatius Reilly [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 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 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 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.
 
  Any help would be wonderful! :)
 
 
 
  Using PHP 4.3.3 on Linux if it matters.
 
  --
  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] 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: 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 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 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: 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...
% 
...
%   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; you'll have to build your final array
from the results.

You can read your info out of the DB as an indexed or associative array
(via mysql_fetch_array) or just as values (mysql_fetch_row), but you'll
only get one result at a time.  You need to loop through the results with
something like

  $result = mysql_query(select id,name from a_table) ;
  $everyone = () ;
  while ( $row = mysql_fetch_array($result) )
{ $everyone[$row['id']] = $row['name'] ; }

or so to fill up $everyone so that you can then look up by $everyone[$id].

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 better
approach is to make your select call per specific ID and get out only the
name(s) that you need, and then go back later and make a different call.
The only time I can see sense in scanning the whole table is when you
want to dump the entire list of people or some such, and then rather than
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 by department ;
  $result = mysql_query($sql) ;
  while ( $row = mysql_fetch_array($result) )
{ print ID: {$row['id']}\tName: {$row['name']}br\n ; }

to just run through the data.  I'm sure others here know of even better
ways to print a roster :-)


% 
% Any help would be wonderful! :)


HTH  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


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 do the job.  I didn't think it worth shooting
down someone who was being helpful, though, when I made my response.


HTH  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


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 time you aren't using
specific key references.

Do the following to see the difference and you'll see why you'll almost always
want to use *_assoc() and not *_array():

?
/**
 * Edit to suit your DB needs
 **/
$query = SELECT * FROM blah;
$result = mysql( $dbname, $query );

echo 'pre';
print_r( mysql_fetch_array( $result ));

echo \n\n;
mysql_data_seek( $result, 0 );
print_r( mysql_fetch_assoc( $result ));

echo '/pre';
?

Especially if you use the foreach() construct, mysql_fetch_array() is bad 
news.

Chris

-- 
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 Jon Kriek
(1) additional overhead
(2) bad script-logic

-- 
Jon Kriek
http://phpfreaks.com

Richard Hutchins [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Chris (Jon Kriek too, I guess),

 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.

 Thanks,
 Rich

  -Original Message-
  From: Chris Boget [mailto:[EMAIL PROTECTED]
  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 )
 
  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: 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] 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 was being helpful, though, 
 when I made my response.

It didn't seem like he was shooting you down.

Chris

-- 
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
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.


% I avoid mysql_fetch_array() like the plague unless there is a very
% specific need.

I'm interested in this...  The manual reports that there is a very
trivial slowdown.  Do you find that to not be true?  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.


% 
% Chris


HTH  TIA  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


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 PROTECTED] wrote in message
news:[EMAIL PROTECTED]

-- 
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 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 uses the colomn names as the 
keys, which is not what I need.


I didn't think it worth shooting down someone who was being helpful, though, 
when I made my response.


It didn't seem like he was shooting you down.

Chris
I appreciate any attempts to help! :)

--
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
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.

Really?  How?  I must be quite confused.

Given a DB table that looks about like

  idname
  01david
  02anna
  03eunice
  04bob
  05celeste
  06fred

then code like

  $result = mysql_query(select id,name from table) ;
  while ( $row = mysql_fetch_assoc($result) )   // or 
mysql_fetch_array($result,MYSQL_ASSOC) for those who like mysql_fetch_array but for 
some reason care about the memory used by a single record
  {
   ...
  }

will yield $row like

  array
  (
'id' = 01,
'name' = 'david'
  )

or so every time.  How on earth is that going to get Devon his desired

  array
  (
'01' = 'david' ,
'02' = 'anna' ,
...
  )

as requested without some php work?


% 
%  I didn't think it worth shooting down someone who was being helpful, though, 
%  when I made my response.
% 
% It didn't seem like he was shooting you down.

No, but IMNSHO he shot a rather rude hole in Ignatius.


% 
% Chris


TIA  HTH  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


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.php.net/unsub.php



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, actually, I am the one who's confused.  I misread the OP's email such
that *_assoc() would do the job.

My bad.
If MySQL had crosstab functionality, that *might* be able to help.

But I still stand by my assertion that *_assoc() is better than *_array() in 
almost all circumstances.

Chris

-- 
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 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 (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 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_array(): 5.769602060318 seconds [18880 rows]

 Same data set in both cases.  While there isn't MUCH difference, using
 assoc gives one a 30% increase in speed in my rudimentary test over array.

 Mysql_fetch_assoc() is faster -- use it.  I've learned something.

 The code:
   $sql = select * from tblApplications;

   list($l,$r) = split( ,microtime());
   $start = $l + $r;
   $r = mysql_query($sql);
   $num = mysql_num_rows($r);
   while( $row = mysql_fetch_assoc($r) ) {
  // echo ;
   }
   list($l, $r) = explode( ,microtime());
   $diff = ((float)$l + (float)$r) - (float)$start;
   echo hr/fetch_assoc(): $diff seconds [$num rows]($r.$l : $start)hr/;

   list($l,$r) = explode( ,microtime());
   $start = ((float)$l + (float)$r);
   $r = mysql_query($sql);
   $num = mysql_num_rows($r);
   while( $row = mysql_fetch_array($r) ) {
  // echo ;
   }
   list($l, $r) = explode( ,microtime());
   $diff = ((float)$l + (float)$r) - (float)$start;
   echo hr/fetch_array(): $diff seconds [$num rows]($r.$l : $start)hr/;

Beckman
---
Peter Beckman  Internet Guy
[EMAIL PROTECTED] http://www.purplecow.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 Ignatius Reilly
Easy, old boys.
Nobody has holed or meant to hole anybody.

Let's keep this ML what it is, that is a great learning and working
instrument.

Ignatius
_
- Original Message -
From: Jon Kriek [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
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.


  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 (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] 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 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
 and if I choose to ignore it, then that's my choice. If it causes a
 significant slowdown in the performance of my script, then it's certainly a
 candidate for optimization.
 Am I missing something else?

foreach(); list(); each();
None are good ideas when iterating through an array generated by *_array().
And I'd hazard to guess that one of the most significant uses of any query is
to iterate through it's result set.

Chris

-- 
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 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 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 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 what I needed.

--
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
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 single record I would
probably do that; it leaves me with only one function to have to remember
and if I have a real need to tune it down to one or the other then I can
specify the array index format.


% 
%  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 PROTECTED] wrote in message
% news:[EMAIL PROTECTED]

Dude, your quoting *really* needs some help...  Oh, Outhouse.  My
condolences.


Thanks  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


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 better
approach is to make your select call per specific ID and get out only the
name(s) that you need, and then go back later and make a different call.
The only time I can see sense in scanning the whole table is when you
want to dump the entire list of people or some such, and then rather than
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 by department ;
  $result = mysql_query($sql) ;
  while ( $row = mysql_fetch_array($result) )
{ print ID: {$row['id']}\tName: {$row['name']}br\n ; }
to just run through the data.  I'm sure others here know of even better
ways to print a roster :-)
% 
% Any help would be wonderful! :)

HTH  HAND

:-D
Indeed, I was trying to simply display a list of the data. I had coded 
the formatting and displaying first, based on the array I described, 
then tackled the MySQL part last. I see now that it prevented me from 
seeing the better idea of removing the array from the equation 
completely. Your information was invaluble.

I did however go with mysql_fetch_assoc instead of mysql_fetch_array for 
efficiency. :)

--
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
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


HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


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 -- you actually had me reading and rereading
the manual pages to try to figure out where my confusion lay!


% 
% My bad.
% If MySQL had crosstab functionality, that *might* be able to help.

I'll take your word for it; I don't know what crosstab is or gets me :-)


% 
% But I still stand by my assertion that *_assoc() is better than *_array() in 
% almost all circumstances.

OK.  I still want to know whether I can trust the manual and believe that
the measure if that betterness is so small as to almost be theoretical
or must instead see how I've been led down the primrose path.


% 
% Chris


Thanks  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


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 by department ;
%   $result = mysql_query($sql) ;
%   while ( $row = mysql_fetch_array($result) )
% { print ID: {$row['id']}\tName: {$row['name']}br\n ; }
% 
% to just run through the data.  I'm sure others here know of even better
% ways to print a roster :-)
...
% 
% Indeed, I was trying to simply display a list of the data. I had coded 
% the formatting and displaying first, based on the array I described, 
% then tackled the MySQL part last. I see now that it prevented me from 

Been there; oops-ed that.  You can even let the DB format your output for
you so that it spits out HTML and then you're *really* on your way to
just dumping the output to the page! :-)


% seeing the better idea of removing the array from the equation 
% completely. Your information was invaluble.

Happy to help!


% 
% I did however go with mysql_fetch_assoc instead of mysql_fetch_array for 
% efficiency. :)

I hear more and more that that's the way to go :-)


HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


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 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 complex. Either way, not sure it would help or be
worth it for this (dead) issue. :)

---John Holmes...

-- 
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
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
...
% 
% foreach(); list(); each();
% None are good ideas when iterating through an array generated by *_array().

Ahhh...  The light begins to dawn.

I only ever use

  while ( $row = fetch )

to go through my rows and then directly handle the fields I pull out, but
I can see that one might loop across $row and for that you need only the
indices that matter.  [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?]


% And I'd hazard to guess that one of the most significant uses of any query is
% to iterate through it's result set.

Well, I typically do loop over the result set but typically don't loop
over the fields in each record, so I don't know that I can agree with the
weight you put on that.  But at least I see why I could care :-)


% 
% Chris


Thanks  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


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
- -- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.7 (FreeBSD)

iD8DBQE/k/xoGb7uCXufRwARApHSAJ45R/0IzE0/pJhLLnsYkz5P03J1BACg6PbK
x+fgoWcYOpWWl45qxCLGEqI=
=B4Vv
-END PGP SIGNATURE-

-- 
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 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 more complex. Either way, not sure it would help or be
 worth it for this (dead) issue. :)

Then I'm not calling it the right thing... just the name of the type of query that
was told.  The kind of query I'm talking about is the one that rotates the result
set from tall to wide.  Basically doing exactly what the OP had asked for.  If
that kind of query isn't called a 'crosstab' query, I'm not sure what the name is.
I know that mysql doesn't support it but PG does (I'm just starting to learn PG).

Chris

-- 
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 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 to use _array() as you'll have the
duplicates to worry about / skip over. using _row() or _assoc() and just
looping through that will suffice.

---John Holmes...

-- 
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 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 the past, but maybe
you're
  thinking of something more complex. Either way, not sure it would help
or be
  worth it for this (dead) issue. :)

 Then I'm not calling it the right thing... just the name of the type of
query that
 was told.  The kind of query I'm talking about is the one that rotates the
result
 set from tall to wide.  Basically doing exactly what the OP had asked for.
If
 that kind of query isn't called a 'crosstab' query, I'm not sure what the
name is.
 I know that mysql doesn't support it but PG does (I'm just starting to
learn PG).

I see. I've always heard it referred to as a pivot table, or something
along those lines.

Great crosstab article/story:
http://www.devshed.com/Server_Side/MySQL/MySQLWiz/page1.html

---John Holmes...

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