[PHP-DB] Re: Dumping MySQL rows into a 2D array

2002-12-13 Thread Bastian Vogt
Hi,

first leave out the loop with for ($i...).
then use the loop with while and make sure that you create arrays. you're
currently filling the same variables with different results each time. the last
one always overwrites the ones bevor.
so add those brackets: []:
 $dbRow['ev_id'][]= $row[id];
 $dbRow['ev_uid'][]   = $row[user_id];
  


HTH,
Bastian

George Pitcher schrieb:

 Hi all,

 I want to grab the resul from a db query and store it in an array so that I
 can selectively grab the data later.

 This is what I'm doing:

 $dbRowCount = mysql_num_rows( $result );
 for ($i = 1; $i = $dbRowCount; ++$i) {
 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
 $dbRow['ev_id']= $row[id];
 $dbRow['ev_uid']   = $row[user_id];
 $dbRow['ev_title'] = $row[name];
 $dbRow['ev_cat']   = $row[category];
 $dbRow['ev_sd']= $row[start_day];
 $dbRow['ev_ed']= $row[end_day];
 }
 }

 In my sample database, I have two records which are both found with the
 query (tested in MySQLFront) but the array ends up with 3 rows each with the
 last record in it.

 Any suggestions?

 George

 ===

 George Pitcher
 HERON Technical Manager
 Ingenta plc
 23-38 Hythe Bridge Street, Oxford, OX1 2ET
 T  +44 (0)1865 799137 direct
 T  +44 (0)1865 799000 switchboard
 F  +44 (0)1865 799134
 E  [EMAIL PROTECTED]

 www.ingenta.com
 Ingenta: Empowering the exchange of academic and professional content
 online.


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




RE: [PHP-DB] Re: Dumping MySQL rows into a 2D array

2002-12-13 Thread George Pitcher
Bastian,

That's great - it does the trick perfectly. Many thanks.

George


 -Original Message-
 From: Bastian Vogt [mailto:[EMAIL PROTECTED]]
 Sent: 13 December 2002 3:18 pm
 To: [EMAIL PROTECTED]
 Subject: [PHP-DB] Re: Dumping MySQL rows into a 2D array
 
 
 Hi,
 
 first leave out the loop with for ($i...).
 then use the loop with while and make sure that you create 
 arrays. you're
 currently filling the same variables with different results each 
 time. the last
 one always overwrites the ones bevor.
 so add those brackets: []:
  $dbRow['ev_id'][]= $row[id];
  $dbRow['ev_uid'][]   = $row[user_id];
   
 
 
 HTH,
 Bastian
 
 George Pitcher schrieb:
 
  Hi all,
 
  I want to grab the resul from a db query and store it in an 
 array so that I
  can selectively grab the data later.
 
  This is what I'm doing:
 
  $dbRowCount = mysql_num_rows( $result );
  for ($i = 1; $i = $dbRowCount; ++$i) {
  while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  $dbRow['ev_id']= $row[id];
  $dbRow['ev_uid']   = $row[user_id];
  $dbRow['ev_title'] = $row[name];
  $dbRow['ev_cat']   = $row[category];
  $dbRow['ev_sd']= $row[start_day];
  $dbRow['ev_ed']= $row[end_day];
  }
  }
 
  In my sample database, I have two records which are both found with the
  query (tested in MySQLFront) but the array ends up with 3 rows 
 each with the
  last record in it.
 
  Any suggestions?
 
  George
 
  ===
 
  George Pitcher
  HERON Technical Manager
  Ingenta plc
  23-38 Hythe Bridge Street, Oxford, OX1 2ET
  T  +44 (0)1865 799137 direct
  T  +44 (0)1865 799000 switchboard
  F  +44 (0)1865 799134
  E  [EMAIL PROTECTED]
 
  www.ingenta.com
  Ingenta: Empowering the exchange of academic and professional content
  online.
 
 
 -- 
 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