[PHP] mysql_fetch_array() vs mysql_fetch_assoc() WAS: Re: [PHP] Why does this script run out of memory?

2011-10-28 Thread Daniel Brown
On Fri, Oct 28, 2011 at 18:13, Paul Halliday paul.halli...@gmail.com wrote:

 Whats the difference between fetch_assoc and fetch_row?

 I use:
 while ($row = mysql_fetch_row($theQuery)) {
    doCartwheel;
 }

 on just under 300 million rows and nothing craps out. I have
 memory_limit set to 4GB though. Although, IIRC I pushed it up for GD
 not mysql issues.

 Same OS and php ver, MySQL is 5.1.48

Please don't hijack other's threads to ask a question.  I've
started this as a new thread to address this question.

mysql_fetch_array() grabs all of the data and places it in a
simple numerically-keyed array.

By contrast, mysql_fetch_assoc() grabs it and populates an
associative array.  This means that the column names (or aliases, et
cetera) become the keys for the array.  With mysql_fetch_assoc(), you
can still call an array key by number, but it's not vice-versa with
mysql_fetch_array().

The difference in overhead, if you meant that (in which case, my
apologies for reading it as a question of functional difference), is
variable: it's based mainly on the difference between the bytes
representing the integers used as keys in mysql_fetch_array() versus
the size in bytes of the strings used as keys in mysql_fetch_assoc().

-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

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



Re: [PHP] mysql_fetch_array() vs mysql_fetch_assoc() WAS: Re: [PHP] Why does this script run out of memory?

2011-10-28 Thread Jim Long
On Fri, Oct 28, 2011 at 06:19:56PM -0400, Daniel Brown wrote:
 On Fri, Oct 28, 2011 at 18:13, Paul Halliday paul.halli...@gmail.com wrote:
 
  Whats the difference between fetch_assoc and fetch_row?
 
  I use:
  while ($row = mysql_fetch_row($theQuery)) {
  ? ?doCartwheel;
  }
 
  on just under 300 million rows and nothing craps out. I have
  memory_limit set to 4GB though. Although, IIRC I pushed it up for GD
  not mysql issues.
 
  Same OS and php ver, MySQL is 5.1.48
 
 Please don't hijack other's threads to ask a question.  I've
 started this as a new thread to address this question.
 
 mysql_fetch_array() grabs all of the data and places it in a
 simple numerically-keyed array.
 
 By contrast, mysql_fetch_assoc() grabs it and populates an
 associative array.  This means that the column names (or aliases, et
 cetera) become the keys for the array.  With mysql_fetch_assoc(), you
 can still call an array key by number, but it's not vice-versa with
 mysql_fetch_array().

I'm not seeing any numeric keys in my mysql_fetch_assoc() arrays.

However, mysql_fetch_row (by default) does both: the array will be
indexed numerically from 0 to N-1 corresponding to the table's N
columns, and the array will also have string key indices which
correspond to the query's column names.  So by default,
mysql_fetch_row uses twice the amount of data, because each field
appears in the array twice.

var_dump( $row ) will show in graphic detail.


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



Re: [PHP] mysql_fetch_array() vs mysql_fetch_assoc() WAS: Re: [PHP] Why does this script run out of memory?

2011-10-28 Thread Daniel Brown
On Fri, Oct 28, 2011 at 18:48, Jim Long p...@umpquanet.com wrote:

 I'm not seeing any numeric keys in my mysql_fetch_assoc() arrays.

You're absolutely correct, that's my mistake: substitute
mysql_fetch_row() for mysql_fetch_assoc().  Duh.

Time to call it a week

-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

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



Re: [PHP] mysql_fetch_array

2007-11-05 Thread Philip Thompson
On 11/3/07, Eduardo Vizcarra [EMAIL PROTECTED] wrote:

 Hi guys

 After doing some changes, I believe it is partially working, what I did is
 the following:
   while($row=mysql_fetch_array($fotos))
   {
$fotos_mostrar[] = $row;
   }
   $primer_foto = reset($fotos_mostrar[0]); // This is to set the pointer
 to
 the first record
 echo $primer_foto; // This displays the first column when doing a SELECT

 However, my SELECT statement retrieves 2 columns from one table, how do I
 display the second column ?

 Thanks
 Eduardo



Since you're pulling 2 columns, why don't you use MYSQL_ASSOC option?
Example...

[code]
$query = SELECT column1, column2 FROM table WHERE (...);
...
while ($row = mysql_fetch_array ($fotos, MYSQL_ASSOC)) {
$fotos_mostrar['col1'][] = $row['column1'];
$fotos_mostrar['col2'][] = $row['column2'];
}
...
// To view the contents of what you just created
echo pre;
print_r ($fotos_mostrar);
echo /pre;
[/code]

By doing it this way, you know exactly what you're storing and where.
Hopefully I didn't muddy things up! ;-)

~Philip


Re: [PHP] mysql_fetch_array

2007-11-04 Thread Jim Lucas

Eduardo Vizcarra wrote:

Hi guys

After doing some changes, I believe it is partially working, what I did is 
the following:

  while($row=mysql_fetch_array($fotos))
  {
   $fotos_mostrar[] = $row;
  }
  $primer_foto = reset($fotos_mostrar[0]); // This is to set the pointer to 
the first record

echo $primer_foto; // This displays the first column when doing a SELECT



if you notice you are referring to an index in your array.

You should be doing the reset on $fotos_mostrar like this

reset($fotos_mostrar);

var_dump($fotos_mostrar);

This will display the entire dataset.

also, if you read the first line just above the first example of use, 
you will notice that it says that reset will return the first array 
element or false.


The reason that you are getting the first column is because in your 
reset call, you are referencing the first index entry in your array.


This would return you the first index of the first index in your array.

NO, I did not just repeat myself.  re-read what I wrote and think it 
through and it will make perfect sense.


So, try what I showed you at the beginning of my comments and you will 
see the results you are wanting.


However, my SELECT statement retrieves 2 columns from one table, how do I 
display the second column ?


Thanks
Eduardo

Jim Lucas [EMAIL PROTECTED] escribió en el mensaje 
news:[EMAIL PROTECTED]

Eduardo Vizcarra wrote:
I have a WHILE sentence to retrieve all records from a SELECT query in a 
database and am using mysql_fetch_array to store them in a matrix, the 
sentence is like this:

  while($row=mysql_fetch_array($fotos))
  {
   $fotos_mostrar[] = $row;
  }

$fotos contains all records found in a db table, the SELECT statement is 
retrieving 2 columns from a table, how do I store all records in a 2 
dimention table so I can use it later ?


this WHILE sentence seems to only store the last record only

Regards

how are you checking to see the contents of the $fotos_mostrar array() ?

just after the while loop ends, do a var_dump() or print_r() on the array 
and view the contents. 




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



Re: [PHP] mysql_fetch_array

2007-11-04 Thread heavyccasey
Do you even need reset()? I've never used it.

On Nov 3, 2007 11:08 PM, Jim Lucas [EMAIL PROTECTED] wrote:
 Eduardo Vizcarra wrote:
  Hi guys
 
  After doing some changes, I believe it is partially working, what I did is
  the following:
while($row=mysql_fetch_array($fotos))
{
 $fotos_mostrar[] = $row;
}
$primer_foto = reset($fotos_mostrar[0]); // This is to set the pointer to
  the first record
  echo $primer_foto; // This displays the first column when doing a SELECT
 

 if you notice you are referring to an index in your array.

 You should be doing the reset on $fotos_mostrar like this

 reset($fotos_mostrar);

 var_dump($fotos_mostrar);

 This will display the entire dataset.

 also, if you read the first line just above the first example of use,
 you will notice that it says that reset will return the first array
 element or false.

 The reason that you are getting the first column is because in your
 reset call, you are referencing the first index entry in your array.

 This would return you the first index of the first index in your array.

 NO, I did not just repeat myself.  re-read what I wrote and think it
 through and it will make perfect sense.

 So, try what I showed you at the beginning of my comments and you will
 see the results you are wanting.


  However, my SELECT statement retrieves 2 columns from one table, how do I
  display the second column ?
 
  Thanks
  Eduardo
 
  Jim Lucas [EMAIL PROTECTED] escribió en el mensaje
  news:[EMAIL PROTECTED]
  Eduardo Vizcarra wrote:
  I have a WHILE sentence to retrieve all records from a SELECT query in a
  database and am using mysql_fetch_array to store them in a matrix, the
  sentence is like this:
while($row=mysql_fetch_array($fotos))
{
 $fotos_mostrar[] = $row;
}
 
  $fotos contains all records found in a db table, the SELECT statement is
  retrieving 2 columns from a table, how do I store all records in a 2
  dimention table so I can use it later ?
 
  this WHILE sentence seems to only store the last record only
 
  Regards
  how are you checking to see the contents of the $fotos_mostrar array() ?
 
  just after the while loop ends, do a var_dump() or print_r() on the array
  and view the contents.
 

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



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



Re: [PHP] mysql_fetch_array

2007-11-04 Thread Jim Lucas

[EMAIL PROTECTED] wrote:

Do you even need reset()? I've never used it.


Personally, I do not see the need.

The op is building the array then wanting to work with it.

At this point, the internal pointer should still be at the beginning. AFAIK

Jim

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



Re: [PHP] mysql_fetch_array

2007-11-03 Thread Jim Lucas

Eduardo Vizcarra wrote:
I have a WHILE sentence to retrieve all records from a SELECT query in a 
database and am using mysql_fetch_array to store them in a matrix, the 
sentence is like this:

  while($row=mysql_fetch_array($fotos))
  {
   $fotos_mostrar[] = $row;
  }

$fotos contains all records found in a db table, the SELECT statement is 
retrieving 2 columns from a table, how do I store all records in a 2 
dimention table so I can use it later ?


this WHILE sentence seems to only store the last record only

Regards 


how are you checking to see the contents of the $fotos_mostrar array() ?

just after the while loop ends, do a var_dump() or print_r() on the 
array and view the contents.


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



Re: [PHP] mysql_fetch_array

2007-11-03 Thread Eduardo Vizcarra
Hi guys

After doing some changes, I believe it is partially working, what I did is 
the following:
  while($row=mysql_fetch_array($fotos))
  {
   $fotos_mostrar[] = $row;
  }
  $primer_foto = reset($fotos_mostrar[0]); // This is to set the pointer to 
the first record
echo $primer_foto; // This displays the first column when doing a SELECT

However, my SELECT statement retrieves 2 columns from one table, how do I 
display the second column ?

Thanks
Eduardo

Jim Lucas [EMAIL PROTECTED] escribió en el mensaje 
news:[EMAIL PROTECTED]
 Eduardo Vizcarra wrote:
 I have a WHILE sentence to retrieve all records from a SELECT query in a 
 database and am using mysql_fetch_array to store them in a matrix, the 
 sentence is like this:
   while($row=mysql_fetch_array($fotos))
   {
$fotos_mostrar[] = $row;
   }

 $fotos contains all records found in a db table, the SELECT statement is 
 retrieving 2 columns from a table, how do I store all records in a 2 
 dimention table so I can use it later ?

 this WHILE sentence seems to only store the last record only

 Regards
 how are you checking to see the contents of the $fotos_mostrar array() ?

 just after the while loop ends, do a var_dump() or print_r() on the array 
 and view the contents. 

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



[PHP] mysql_fetch_array

2007-11-02 Thread Eduardo Vizcarra
I have a WHILE sentence to retrieve all records from a SELECT query in a 
database and am using mysql_fetch_array to store them in a matrix, the 
sentence is like this:
  while($row=mysql_fetch_array($fotos))
  {
   $fotos_mostrar[] = $row;
  }

$fotos contains all records found in a db table, the SELECT statement is 
retrieving 2 columns from a table, how do I store all records in a 2 
dimention table so I can use it later ?

this WHILE sentence seems to only store the last record only

Regards 

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



Re: [PHP] mysql_fetch_array

2007-11-02 Thread Cristian Vrabie
this is most peculiar. your code should do exactly what you expect. have 
you initialized the $fotos_mostrar array before the while loop?

$fotos_mostrar = array();


Eduardo Vizcarra wrote:
I have a WHILE sentence to retrieve all records from a SELECT query in a 
database and am using mysql_fetch_array to store them in a matrix, the 
sentence is like this:

  while($row=mysql_fetch_array($fotos))
  {
   $fotos_mostrar[] = $row;
  }

$fotos contains all records found in a db table, the SELECT statement is 
retrieving 2 columns from a table, how do I store all records in a 2 
dimention table so I can use it later ?


this WHILE sentence seems to only store the last record only

Regards 

  


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



Re: [PHP] mysql_fetch_array

2007-11-02 Thread Eduardo Vizcarra
Yes, matrix has been defined just before this WHILE sentence
Cristian Vrabie [EMAIL PROTECTED] escribió en el mensaje 
news:[EMAIL PROTECTED]
 this is most peculiar. your code should do exactly what you expect. have 
 you initialized the $fotos_mostrar array before the while loop?
 $fotos_mostrar = array();


 Eduardo Vizcarra wrote:
 I have a WHILE sentence to retrieve all records from a SELECT query in a 
 database and am using mysql_fetch_array to store them in a matrix, the 
 sentence is like this:
   while($row=mysql_fetch_array($fotos))
   {
$fotos_mostrar[] = $row;
   }

 $fotos contains all records found in a db table, the SELECT statement is 
 retrieving 2 columns from a table, how do I store all records in a 2 
 dimention table so I can use it later ?

 this WHILE sentence seems to only store the last record only

 Regards
 

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



Re: [PHP] mysql_fetch_array

2007-11-02 Thread Richard S. Crawford
On Friday 02 November 2007 18:23:03 Eduardo Vizcarra wrote:
   while($row=mysql_fetch_array($fotos))
   {
    $fotos_mostrar[] = $row;
   }

 $fotos contains all records found in a db table, the SELECT statement is
 retrieving 2 columns from a table, how do I store all records in a 2
 dimention table so I can use it later ?

 this WHILE sentence seems to only store the last record only

That is peculiar; assuming that your query is properly executed and the code 
you're using to display the contents of $fotos_mostrar is written properly.  
Can you show us that code?


-- 
Richard S. Crawford
Editor-in-chief, Daikaijuzine (http://www.daikaijuzine.com)
Personal website: http://www.mossroot.com
Support me in the 2007 Write-a-thon:
http://www.firstgiving.com/richardscrawford

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



[PHP] mysql_fetch_array to associative array

2007-07-16 Thread Andras Kende
Hello,

I use the following GetArray for returning an array from mysql results.

But having a hard time modifying it for returning a simple associative array

Like:

$conn-GetAssoc('SELECT id, name from manufacturers')

Array ( [2] = BMW [1] = MAZDA [9] = FORD )


function GetArray($query) {
$get = $this-Execute ( $query );

$row_id = 0;
while ( $row = mysql_fetch_array($get) ) {
foreach ( $row as $key = $value )
$result[$row_id][$key] = $value;
$row_id++;
}
mysql_free_result($get);

return $result;
}


function GetAssoc($query) {
$get = $this-Execute ( $query );

$row_id = 0;
while ( $row = mysql_fetch_array($get) ) {

?

}
mysql_free_result($get);

return $result;
}

I searched a lot but didn't find anything.

Thanks for any help :)

Andras

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



Re: [PHP] mysql_fetch_array to associative array

2007-07-16 Thread Robert Cummings
On Mon, 2007-07-16 at 07:41 -0700, Andras Kende wrote:
 Hello,
 
 I use the following GetArray for returning an array from mysql results.
 
 But having a hard time modifying it for returning a simple associative array
 
 Like:
 
 $conn-GetAssoc('SELECT id, name from manufacturers')
 
 Array ( [2] = BMW [1] = MAZDA [9] = FORD )
 
 
   function GetArray($query) {
   $get = $this-Execute ( $query );
   
  $result = array();
   while ( $row = mysql_fetch_array($get) ) {
  $result[] = $row;
   }
   mysql_free_result($get);
   
   return $result;
   }
 
 
   function GetAssoc($query) {
   $get = $this-Execute ( $query );
   
  $result = array();
   while ( $row = mysql_fetch_array($get) ) {
  $result[] = $row;
 
   }
   mysql_free_result($get);
   
   return $result;
   }
 
 I searched a lot but didn't find anything.
 
 Thanks for any help :)

You're welcome.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



Re: [PHP] mysql_fetch_array to associative array

2007-07-16 Thread Robert Cummings
On Mon, 2007-07-16 at 10:52 -0400, Robert Cummings wrote:
 On Mon, 2007-07-16 at 07:41 -0700, Andras Kende wrote:
  Hello,
  
  I use the following GetArray for returning an array from mysql results.
  
  But having a hard time modifying it for returning a simple associative array
  
  Like:
  
  $conn-GetAssoc('SELECT id, name from manufacturers')
  
  Array ( [2] = BMW [1] = MAZDA [9] = FORD )
  
  
  function GetArray($query) {
  $get = $this-Execute ( $query );
  
   $result = array();
  while ( $row = mysql_fetch_array($get) ) {
   $result[] = $row;
  }
  mysql_free_result($get);
  
  return $result;
  }
  
  
  function GetAssoc($query) {
  $get = $this-Execute ( $query );
  
   $result = array();
  while ( $row = mysql_fetch_array($get) ) {

You should probably use mysql_fetch_assoc() in the above line.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



Re: [PHP] mysql_fetch_array to associative array

2007-07-16 Thread Jim Lucas

Andras Kende wrote:

Hello,

I use the following GetArray for returning an array from mysql results.

But having a hard time modifying it for returning a simple associative array

Like:

$conn-GetAssoc('SELECT id, name from manufacturers')

Array ( [2] = BMW [1] = MAZDA [9] = FORD )


function GetArray($query) {
$get = $this-Execute ( $query );



don't you need to check to make sure that $get is a valid resource???

$result = array();


while ( $row = mysql_fetch_array($get) ) {


All of this can be replace with this one line
$result[] = $row;


}
mysql_free_result($get);

return $result;
}


function GetAssoc($query) {
$get = $this-Execute ( $query );



don't you need to check to make sure that $get is a valid resource???

$result = array();


while ( $row = mysql_fetch_assoc($get) ) {


$result[] = $row;


}
mysql_free_result($get);

return $result;
}

I searched a lot but didn't find anything.

Thanks for any help :)

Andras




--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

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



RE: [PHP] mysql_fetch_array to associative array

2007-07-16 Thread Andras Kende


-Original Message-
From: Robert Cummings [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 16, 2007 7:52 AM
To: Andras Kende
Cc: php-general@lists.php.net
Subject: Re: [PHP] mysql_fetch_array to associative array

On Mon, 2007-07-16 at 07:41 -0700, Andras Kende wrote:
 Hello,
 
 I use the following GetArray for returning an array from mysql results.
 
 But having a hard time modifying it for returning a simple associative
array
 
 Like:
 
 $conn-GetAssoc('SELECT id, name from manufacturers')
 
 Array ( [2] = BMW [1] = MAZDA [9] = FORD )
 
 
   function GetArray($query) {
   $get = $this-Execute ( $query );
   
  $result = array();
   while ( $row = mysql_fetch_array($get) ) {
  $result[] = $row;
   }
   mysql_free_result($get);
   
   return $result;
   }
 
 
   function GetAssoc($query) {
   $get = $this-Execute ( $query );
   
  $result = array();
   while ( $row = mysql_fetch_array($get) ) {
  $result[] = $row;
 
   }
   mysql_free_result($get);
   
   return $result;
   }
 
 I searched a lot but didn't find anything.
 
 Thanks for any help :)

You're welcome.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...



Hi Rob,

Thanks for your help, its associative but I forget to mention its needs
To be a single dimensional associative array.


$result = array();
while ( $row = mysql_fetch_assoc($get) ) {
$result[] = $row;
}

This creates multi dimensional like:

Array ( [0] = Array ( [0] = 3 [1] = BMW ) [1] = Array ( [0] = 1 [1] =
Mercedes ) )

I tried to play with foreach and array_push but still not perfect

Thanks,

Andras

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



RE: [PHP] mysql_fetch_array to associative array

2007-07-16 Thread Robert Cummings
On Mon, 2007-07-16 at 13:37 -0700, Andras Kende wrote:
 
 Hi Rob,
 
 Thanks for your help, its associative but I forget to mention its needs
 To be a single dimensional associative array.
 
 
 $result = array();
 while ( $row = mysql_fetch_assoc($get) ) {
 $result[] = $row;
 }
 
 This creates multi dimensional like:
 
 Array ( [0] = Array ( [0] = 3 [1] = BMW ) [1] = Array ( [0] = 1 [1] =
 Mercedes ) )
 
 I tried to play with foreach and array_push but still not perfect

I'm not sure I understand... you have multiple rows being returned do
you not? How to you intend to handle them in a single level array?

Let's image the following rows are returned from the database:

array
(
'title' = 'The Dragonbone Chair',
'author' = 'Tad Williams',
),
array
(
'title' = 'Sword of Shannarah',
'author' = 'Terry Brooks',
),

Show me how you would like the final array to look and I can figure out
the code you need to organize it the way you want.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



RE: [PHP] mysql_fetch_array to associative array

2007-07-16 Thread Andras Kende


-Original Message-
From: Robert Cummings [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 16, 2007 1:46 PM
To: Andras Kende
Cc: php-general@lists.php.net
Subject: RE: [PHP] mysql_fetch_array to associative array

On Mon, 2007-07-16 at 13:37 -0700, Andras Kende wrote:
 
 Hi Rob,
 
 Thanks for your help, its associative but I forget to mention its needs
 To be a single dimensional associative array.
 
 
 $result = array();
 while ( $row = mysql_fetch_assoc($get) ) {
 $result[] = $row;
 }
 
 This creates multi dimensional like:
 
 Array ( [0] = Array ( [0] = 3 [1] = BMW ) [1] = Array ( [0] = 1 [1]
=
 Mercedes ) )
 
 I tried to play with foreach and array_push but still not perfect

I'm not sure I understand... you have multiple rows being returned do
you not? How to you intend to handle them in a single level array?

Let's image the following rows are returned from the database:

array
(
'title' = 'The Dragonbone Chair',
'author' = 'Tad Williams',
),
array
(
'title' = 'Sword of Shannarah',
'author' = 'Terry Brooks',
),

Show me how you would like the final array to look and I can figure out
the code you need to organize it the way you want.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

Hi Rob,

$conn-getassoc(select id,name from cars)

I would need a single array like: (its for used with pear:quickform
dropdown)

Array ( [2] = BMW [1] = FORD )

Or:

Array ( [The Dragonbone Chair] = 'Tad Williams' [Sword of Shannarah] =
'Terry Brooks' )


Thanks a lot,

Andras

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



RE: [PHP] mysql_fetch_array to associative array

2007-07-16 Thread Robert Cummings
On Mon, 2007-07-16 at 13:37 -0700, Andras Kende wrote:
 
  function GetAssoc($query) {
  $get = $this-Execute ( $query );
  
   $result = array();
  while ( $row = mysql_fetch_array($get) ) {
   $result[] = $row;
  
  }
  mysql_free_result($get);
  
  return $result;
  }

I'll focus on the above one since that's probably what's causing your
grief... I'm also going to rename it so it's more explanatory:

?php

function GetPairs( $query, $keyField, $valueField )
{
$pairs = array();

if( ($get = $this-Execute ( $query )) )
{
while( ($row = mysql_fetch_assoc( $get )) )
{
$pairs[$row[$keyField]] = $row[$valueField];
}

mysql_free_result( $get );
}

return $pairs;
}

?

That's the function... it creates an array of pair mappings based on the
table fields $keyField and $valueField. So let's say you have the
following table in your database:

CREATE TABLE cars
(
id  int   not null  auto_increment,
namevarchar( 32 ) not null,

primary key( id )
);


Then you might issue the following function call:

?php

$query = SELECT id, name FROM cars ORDER BY name ASC ;

$pairs = GetPairs( $query, 'id', 'name' );

?

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



RE: [PHP] mysql_fetch_array to associative array

2007-07-16 Thread Andras Kende


-Original Message-
From: Robert Cummings [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 16, 2007 6:12 PM
To: Andras Kende
Cc: php-general@lists.php.net
Subject: RE: [PHP] mysql_fetch_array to associative array

On Mon, 2007-07-16 at 13:37 -0700, Andras Kende wrote:
 
  function GetAssoc($query) {
  $get = $this-Execute ( $query );
  
   $result = array();
  while ( $row = mysql_fetch_array($get) ) {
   $result[] = $row;
  
  }
  mysql_free_result($get);
  
  return $result;
  }

I'll focus on the above one since that's probably what's causing your
grief... I'm also going to rename it so it's more explanatory:

?php

function GetPairs( $query, $keyField, $valueField )
{
$pairs = array();

if( ($get = $this-Execute ( $query )) )
{
while( ($row = mysql_fetch_assoc( $get )) )
{
$pairs[$row[$keyField]] = $row[$valueField];
}

mysql_free_result( $get );
}

return $pairs;
}

?

That's the function... it creates an array of pair mappings based on the
table fields $keyField and $valueField. So let's say you have the
following table in your database:

CREATE TABLE cars
(
id  int   not null  auto_increment,
namevarchar( 32 ) not null,

primary key( id )
);


Then you might issue the following function call:

?php

$query = SELECT id, name FROM cars ORDER BY name ASC ;

$pairs = GetPairs( $query, 'id', 'name' );

?

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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





Rob,

THANKS 

I also hacked together a version:

while ( $row = mysql_fetch_array($get) ) {
$result[$row[0]] = $row[1];
}



Best regards,

Andras 

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



Re: [PHP] mysql_fetch_array()

2004-08-18 Thread Chris Shiflett
--- Anthony Ritter [EMAIL PROTECTED] wrote:
 When using mysql_fetch_array() is it necsessary to specify the
 second argument - meaning the constant of MYSQL_NUM or
 MYSQL_ASSOC?

Whenever you have a question about a function, you can look it up using a
URL formatted as follows:

http://www.php.net/mysql_fetch_array

Here, you will see:

The optional second argument result_type  in mysql_fetch_array() is a
constant and can take the following values: MYSQL_ASSOC, MYSQL_NUM, and
MYSQL_BOTH. This feature was added in PHP 3.0.7. MYSQL_BOTH is the default
for this argument.

By using MYSQL_BOTH, you'll get an array with both associative and number
indices. Using MYSQL_ASSOC, you only get associative indices (as
mysql_fetch_assoc() works), using MYSQL_NUM, you only get number indices
(as mysql_fetch_row() works).

Hope that helps.

Chris

=
Chris Shiflett - http://shiflett.org/

PHP Security - O'Reilly
 Coming Fall 2004
HTTP Developer's Handbook - Sams
 http://httphandbook.org/
PHP Community Site
 http://phpcommunity.org/

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



Re: [PHP] mysql_fetch_array()

2004-08-18 Thread Anthony Ritter
Thank you Chris.

My question was the call to

mysql_fetch_array()

will also return a result set without the additional argument constant as
in:

while ($row = mysql_fetch_array($sql))
 {...
 // no constant is being used

There are many times that I see that used in textbooks - without the
constant - just the variable from the sql query as the argument.

TR


---
[This E-mail scanned for viruses by gonefishingguideservice.com]

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



Re: [PHP] mysql_fetch_array()

2004-08-18 Thread Chris Shiflett
--- Anthony Ritter [EMAIL PROTECTED] wrote:
 My question was the call to
 
 mysql_fetch_array()
 
 will also return a result set without the additional argument
 constant as in:
 
 while ($row = mysql_fetch_array($sql))
  {...
  // no constant is being used
 
 There are many times that I see that used in textbooks - without
 the constant - just the variable from the sql query as the
 argument.

This is what I was talking about, too. That optional argument is described
on the man page in the part I quoted.

If you don't put it, you get both the associative and enumerated arrays.
If you only want one or the other, you can use that optional second
parameter or the separate functions.

Chris

=
Chris Shiflett - http://shiflett.org/

PHP Security - O'Reilly
 Coming Fall 2004
HTTP Developer's Handbook - Sams
 http://httphandbook.org/
PHP Community Site
 http://phpcommunity.org/

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



[PHP] mysql_fetch_array()

2004-08-17 Thread Anthony Ritter
When using mysql_fetch_array() is it necsessary to specify the second
argument - meaning the constant of MYSQL_NUM or MYSQL_ASSOC?

I have seen many examples where it is left out and it is coded:

$row = mysql_fetch_array($sql);

as opposed to

$row = mysql_fetch_array($sql, MYSQL_BOTH);

Thank you.
TR

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



Re: [PHP] mysql_fetch_array()

2004-08-17 Thread John Holmes
Anthony Ritter wrote:
When using mysql_fetch_array() is it necsessary to specify the second
argument - meaning the constant of MYSQL_NUM or MYSQL_ASSOC?
I have seen many examples where it is left out and it is coded:
$row = mysql_fetch_array($sql);
as opposed to
$row = mysql_fetch_array($sql, MYSQL_BOTH);
Note that you can use mysql_fetch_row for the equiv. of MYSQL_NUM and 
mysql_fetch_assoc() for the equiv. of MYSQL_ASSOC. It's sort of a waste 
of resources to use mysql_fetch_array() when you really only use one or 
the other, but a lot of people do it.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] mysql_fetch_array problem? O.o

2004-04-15 Thread Burhan Khalid
Jeff Ostapchuk wrote:

Ok, I have no clue what version of PHP I have installed, 4.??.??, and I have
like the newest version of MySQL insatlled, and PHP and MySQL work fine
together, excpet when I use mysql_fetch_row($query)   then I have problems,
mysql_fetch_array($query) works fine, but not mysql_fetch_row($query). Why
doesn't it work? I tried installing the new PHP 5 version, but when i
extracted it from the zip file into the C:\PHP folder and then PHP didn't
even work at all (so... u can kinda tell i'm a still a noobie at this
^.^;;; ) Thank in advance to whoever.
mysql_fetch_row() will return false if you are already on the last row 
in your result set.

You also need to pass both mysql_fetch_array() and mysql_fetch_row() the 
resource id from a successful mysql_query() call.

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


[PHP] mysql_fetch_array problem? O.o

2004-04-14 Thread Jeff Ostapchuk
Ok, I have no clue what version of PHP I have installed, 4.??.??, and I have
like the newest version of MySQL insatlled, and PHP and MySQL work fine
together, excpet when I use mysql_fetch_row($query)   then I have problems,
mysql_fetch_array($query) works fine, but not mysql_fetch_row($query). Why
doesn't it work? I tried installing the new PHP 5 version, but when i
extracted it from the zip file into the C:\PHP folder and then PHP didn't
even work at all (so... u can kinda tell i'm a still a noobie at this
^.^;;; ) Thank in advance to whoever.

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



Re: [PHP] mysql_fetch_array problem? O.o

2004-04-14 Thread Richard Davey
Hello Jeff,

Thursday, April 15, 2004, 3:18:53 AM, you wrote:

JO Ok, I have no clue what version of PHP I have installed, 4.??.??, and I have

Find out:

?
  echo phpinfo();
?

(view it in a browser)

JO like the newest version of MySQL insatlled, and PHP and MySQL work fine
JO together, excpet when I use mysql_fetch_row($query)   then I have problems,

What error does it give you? What actually happens? Post some of your
code perhaps?

More info needed, mysql_fetch_row certainly works so whatever the
cause, it's AYE (at your end).

-- 
Best regards,
 Richard Davey
 http://www.phpcommunity.org/wiki/296.html

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



[PHP] mysql_fetch_array

2004-03-26 Thread Chris Mach
I have this query to select the date from my table...

SELECT DATE_FORMAT(date1, '%W %M %Y') FROM table

How do I know what name mysql_fetch_array assigned to the date_format ?





Re: [PHP] mysql_fetch_array

2004-03-26 Thread Adam Voigt
It would be position 0 in the array, or in your query after the date
format function you could put AS blah and then it would come out as
blah.


On Fri, 2004-03-26 at 13:50, Chris Mach wrote:
 I have this query to select the date from my table...
 
 SELECT DATE_FORMAT(date1, '%W %M %Y') FROM table
 
 How do I know what name mysql_fetch_array assigned to the date_format ?
 
-- 

Adam Voigt
[EMAIL PROTECTED]

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



Re: [PHP] mysql_fetch_array

2004-03-26 Thread John W. Holmes
From: Adam Voigt [EMAIL PROTECTED]
 On Fri, 2004-03-26 at 13:50, Chris Mach wrote:
 
  I have this query to select the date from my table...
 
  SELECT DATE_FORMAT(date1, '%W %M %Y') FROM table
 
  How do I know what name mysql_fetch_array assigned to the date_format ?

 It would be position 0 in the array, or in your query after the date
 format function you could put AS blah and then it would come out as
 blah.

Or you could use $row['DATE_FORMAT(date1, \'%W %M %Y\')'], but... umm..
yeah

;)

---John Holmes...

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



Re: [PHP] mysql_fetch_array

2004-03-26 Thread Tom Rogers
Hi,

Saturday, March 27, 2004, 4:50:27 AM, you wrote:
CM I have this query to select the date from my table...

CM SELECT DATE_FORMAT(date1, '%W %M %Y') FROM table

CM How do I know what name mysql_fetch_array assigned to the date_format ?


SELECT DATE_FORMAT(date1, '%W %M %Y') AS date_formatted FROM table

Then access it as date_formatted

-- 
regards,
Tom

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



[PHP] mysql_fetch_array() not working as expected

2003-10-07 Thread Chris W. Parker
Hey peeps.

Let me make this simple. I've got the following sql query in a function:

SELECT c.id
, cc.id
, cc.prod_id
, p.name
, cc.price
, cc.qty
FROM cart AS c
INNER JOIN cart_contents AS cc
ON cc.cart_id = c.id
INNER JOIN products AS p
ON p.id = cc.prod_id
WHERE c.cust_id = '6'
ORDER BY cc.id

When I get the result and turn it into an array with
mysql_fetch_array($var, MYSQL_BOTH) I see the following with print_r():

Array
(
[0] = Array
(
[0] = 2
[id] = 3
[1] = 3
[2] = SDG6004-XX-XXX
[prod_id] = SDG6004-XX-XXX
[3] = Model 6004
[name] = Model 6004
[4] = 89.00
[price] = 89.00
[5] = 2
[qty] = 2
)
)

Notice that index 1 does not have a textual companion like the other
indexes do. I expected the array to be created like this:

Array
(
[0] = Array
(
[0] = 2
[c.id] = 3
[1] = 3
[cc.id] = 3
[2] = SDG6004-XX-XXX
[cc.prod_id] = SDG6004-XX-XXX
[3] = Model 6004
[p.name] = Model 6004
[4] = 89.00
[cc.price] = 89.00
[5] = 2
[cc.qty] = 2
)
)

But alas... that's not how it works.


Anyway to get what I want?



Thanks,
Chris.

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



Re: [PHP] mysql_fetch_array() not working as expected

2003-10-07 Thread Marek Kilimajer
Chris W. Parker wrote:
Hey peeps.

Let me make this simple. I've got the following sql query in a function:

SELECT c.id
, cc.id
, cc.prod_id
, p.name
, cc.price
, cc.qty
FROM cart AS c
INNER JOIN cart_contents AS cc
ON cc.cart_id = c.id
INNER JOIN products AS p
ON p.id = cc.prod_id
WHERE c.cust_id = '6'
ORDER BY cc.id
When I get the result and turn it into an array with
mysql_fetch_array($var, MYSQL_BOTH) I see the following with print_r():
Array
(
[0] = Array
(
[0] = 2
[id] = 3
[1] = 3
[2] = SDG6004-XX-XXX
[prod_id] = SDG6004-XX-XXX
[3] = Model 6004
[name] = Model 6004
[4] = 89.00
[price] = 89.00
[5] = 2
[qty] = 2
)
)
Notice that index 1 does not have a textual companion like the other
indexes do. I expected the array to be created like this:
Array
(
[0] = Array
(
[0] = 2
[c.id] = 3
[1] = 3
[cc.id] = 3
[2] = SDG6004-XX-XXX
[cc.prod_id] = SDG6004-XX-XXX
[3] = Model 6004
[p.name] = Model 6004
[4] = 89.00
[cc.price] = 89.00
[5] = 2
[cc.qty] = 2
)
)
But alas... that's not how it works.

Anyway to get what I want?



Thanks,
Chris.
As you can see only column names create indexes, not table_name dot 
column_name. And thus your second id (cc.id) overwrites the first one (c.id)
You can make the query:
SELECT c.id
	, cc.id AS ccid
	, cc.prod_id
	, p.name

and you will get $row['id'] and $row['ccid']

Marek

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


RE: [PHP] mysql_fetch_array() not working as expected

2003-10-07 Thread Chris W. Parker
Marek Kilimajer mailto:[EMAIL PROTECTED]
on Tuesday, October 07, 2003 12:26 PM said:

 (c.id) You can make the query:
 SELECT c.id
   , cc.id AS ccid
   , cc.prod_id
   , p.name

doh! how obvious!

thanks.



c.

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



[PHP] mysql_fetch_array(): supplied argument is not a valid MySQL result resource

2003-06-12 Thread Ben Houlton
I'm trying to make a PHP script that automaticly makes a link on the side
menu to the id page that was just made, under certain catagories. But I
edited my code to cleen up soem errors and all of a sudden 3 errors came up,
and I haven't been able to fix them! They are:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in C:\Inetpub\wwwroot\main\menu.php on line 29
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in C:\Inetpub\wwwroot\main\menu.php on line 41
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in C:\Inetpub\wwwroot\main\cat.php on line 39

The code for the menu and cat *.php files are below:

menu.php:
HTML

HEAD

  link href=/css/base.css rel=STYLESHEET type=text/css

/HEAD

BODY

  TABLE width=100% cellPadding=0 cellSpacing=0

TR

  TD width=150 vAlign=top

?php

  $register_globals;

  $db = mysql_connect(localhost,root);

  mysql_select_db(common,$db);

  $result = mysql_query(SELECT * FROM main,$db);

  echo centerMain/centerbr;

  while ($row1 = mysql_fetch_array($result)) {

if ($row1[cat] == 1) {

  printf(a href=\pages.php?cat=1id=%s\%s/abr,
$row1[id], $row1[title]);

}

  }

  echo centerMisc./centerbr;

  while ($row1 = mysql_fetch_array($result)) {

if ($row1[cat] == 2) {

  printf(a href=\pages.php?cat=2id=%s\%s/abr,
$row1[id], $row1[title]);

}

  }

?

  /TD

  TD

cat.php:

?php

  if ($submit) {

if ($id) {

  $sql = UPDATE main SET content='$content', title='$title' cat='$cat'
WHERE id=$id;

} else {

  $sql = INSERT INTO main (content,title,cat) VALUES
('$content','$title','$cat');

}

$result = mysql_query($sql);

echo Record updated/edited!pReturn to A
href=\pages.php?cat=$catid=$id\Index/a.;

  } elseif ($delete == areyousure) {

$sql = SELECT * FROM main WHERE id=$id;

$result = mysql_query($sql);

echo Are you sure you want to delete $title?pa
href=\$PHP_SELF?cat=$catid=$iddelete=true\Yes/a | a
href=\$PHP_SELF\No/a;

  } elseif ($delete == true) {

$sql = DELETE FROM main WHERE id=$id;

$result = mysql_query($sql);

echo $title Record deleted!pa
href=\$PHP_SELF?cat=$catid=$cat\Return/a;

  } else {

$result = mysql_query(SELECT * FROM main,$db);

while ($row = mysql_fetch_array($result)) {

  if ($id == $row[id]  $cat == $row[cat]) {

printf(centerfont size=5%s/font/centerbrbr,
$row[title]);

printf(%sbrbr, $row[content]);

printf(a
href=\$PHP_SELF?cat=$catid=%sdelete=areyousure\(DELETE)/abr,
$row[id]);

printf(a
href=\$PHP_SELF?cat=$catid=%sedit_add=$cat\(EDIT)/abr,
$row[id]);

  }

}

echo Pa href=\$PHP_SELF?cat=$catedit_add=$cat\ADD A
RECORD/aP;

  }

?

?php

  if ($edit_add) {

?

  form method=post action=pages.php?cat=?php echo $cat ?

  ?php

if ($id) {

  $sql = SELECT * FROM main WHERE id=$id;

  $result = mysql_query($sql);

  $row = mysql_fetch_array($result);

  $id = $row[id];

  $title = $row[title];

  $cat = $row[cat];

  $content = $row[content];

?

input type=hidden name=id value=?php echo $id ?

  ?php

}

  ?

  TABLE cellPadding=0 cellSpacing=0 border=0

TR

  TDTitle:/TD

  TDinput type=Text name=title value=?php echo $title ?/TD

  TD rowSpan=2 vAlign=Top

TABLE border=0 cellPadding=0 cellSpacing=0
  ?php

$result = mysql_query(SELECT * FROM cat,$db);

while ($cat = mysql_fetch_array($result)) {

  printf(TRTD%s/TDTDinput type=\radio\ name=\cat\
value=\%s\/TD/TR, $cat[name], $cat[id]);

}

  ?/TD/TR/TABLE/TD/TR

TR

  TDMessage:/TD

  TD rowSpan=3textarea name=content rows=7 cols=40
wrap=virtual?php echo $content ?/TEXTAREA/TD/TR/TABLE

  input type=Submit name=submit value=Enter information

  /form

?php

  }

?


Anny help would be highly appreciated!
Thank You for your time.

-Ben



Re: [PHP] mysql_fetch_array(): supplied argument is not a validMySQL result resource

2003-06-12 Thread Philip Olson

It has to do with you assuming everything will work 100% 
of the time.  It won't.  mysql_query() returns false on 
failure, check for that.  Read this recent thread:

 http://marc.theaimsgroup.com/?l=php-generalm=105517588819420

Also, this faq explains it:

 http://www.php.net/manual/en/faq.databases.php#faq.databases.mysqlresource

Btw, what do you expect: $register_globals; to do in your
code?  It won't do anything useful.

Regards,
Philip





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



[PHP] mysql_fetch_array problem

2002-08-11 Thread Jonni

hi everyone!  i'm new here (and new to php) and have a question.  i'm trying
to run a simple blogger type script but am running into a problem i can't
seem to troubleshoot.  first, the three items i put into the database aren't
showing up on my page and then when i try to go to the archive for the
month, i get the following:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in /home/blar/public_html/inc/main_inc.php on line 11

here's a part of my code of main_inc (first line is line 11):
function showPosts($result,$page)
{
 if ($myrow = mysql_fetch_array($result))
 {
  do
  {
   $rawdate = $myrow[postDate];
   $formdate = date(l, F j, Y,
(strtotime(ereg_replace('([0-9]*)-([0-9]*)-([0-9]*)','\2/\3/\1',
$rawdate;
   if ($date != $formdate)
   {
$date = $formdate;
?

!-- Formatting for date --
b?=$formdate;?/bbr
nbsp;br

?
   }
   if ($page == 1)
   {
showArchivePost($myrow);
   }
   else
   {
showMainPost($myrow);
   }
  }
  while ($myrow = mysql_fetch_array($result));
 }
}
/code

thank in advance for any help.  :)

jonni b.
http://blar.org
http://uglypropaganda.com




Re: [PHP] mysql_fetch_array errors

2002-05-20 Thread Philip Olson

A key to understanding your mysql errors is by using 
the mysql_error() function.  It's wonderful!  Here's 
a simple example with a little error checking:


?php
  error_reporting(E_ALL);

  $conn = mysql_connect('host','user','pass');

  if (!$conn) {
print Could not connect to mysql :  . mysql_error();
exit;
  }

  mysql_select_db('dbname');

  $sql = SELECT foo,bar FROM blah;

  $result = mysql_query($sql);

  // mysql_query returns false on failure.
  if (!$result) {
print Could not query DB ($sql) :  . mysql_error();
exit;
  }

  while($row = mysql_fetch_assoc($result)) {

extract($row);

print Hello $foo, I like $bar too\n;
  }

? 


Regards,
Philip Olson


On Sun, 19 May 2002, Justin Latham wrote:

 I am trying to clone my webserver because I am switching ISPs.  So I copied
 the MySQL database, and then I copied the php pages.  But my new server
 insists that any query I do is not a valid result resource when I try to use
 it in a mysql_fetch_array command.  I know that both php and the database
 are functional (to an extent) because all other commands work.
 I'm using PHP 4.something over MySQL 3.2.3 running RedHat 7.0.
 Thanks
 
 Justin
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 



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




[PHP] mysql_fetch_array errors

2002-05-19 Thread Justin Latham

I am trying to clone my webserver because I am switching ISPs.  So I copied
the MySQL database, and then I copied the php pages.  But my new server
insists that any query I do is not a valid result resource when I try to use
it in a mysql_fetch_array command.  I know that both php and the database
are functional (to an extent) because all other commands work.
I'm using PHP 4.something over MySQL 3.2.3 running RedHat 7.0.
Thanks

Justin



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




Re: [PHP] mysql_fetch_array errors

2002-05-19 Thread Richard Archer

At 9:38 PM -0400 19/5/02, Justin Latham wrote:

insists that any query I do is not a valid result resource when I try to use
it in a mysql_fetch_array command.  I know that both php and the database

So what errors are being returned by all the mysql_* calls?

Error messages are their to help the programmer find problems...
not as an annoyance to be turned off and/or ignored.

 ...R.

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




[PHP] mysql_fetch_array()

2002-04-05 Thread Phil Ewington

Hi All,

I am new to PHP and am having a bit of trouble. I have a recordset using...

$events = mysql_fetch_array($recordset);

this drags in 3 columns from my table...

event_id, event_title, event_date

I want to search the recordset for a given date, if found I want to be able
to reference event_id  event_title from the row. I am using PHP 4.01.

TIA

Phil Ewington.

---
P.S. If there are any ColdFusion developers on this list, what is the PHP
equivalent of a structure?


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




Re: [PHP] mysql_fetch_array()

2002-04-05 Thread Ben Edwards

$db = mysql_open();

$results = mysql_query( select * from something, $db );

while( $row = mysql_fetch_array( $results ) ) {
  processing using $row[column] as reference
}


Ben

At 11:21 05/04/2002, Phil Ewington wrote:

Hi All,

I am new to PHP and am having a bit of trouble. I have a recordset using...

$events = mysql_fetch_array($recordset);

this drags in 3 columns from my table...

event_id, event_title, event_date

I want to search the recordset for a given date, if found I want to be able
to reference event_id  event_title from the row. I am using PHP 4.01.

TIA

Phil Ewington.

---
P.S. If there are any ColdFusion developers on this list, what is the PHP
equivalent of a structure?


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


* Ben Edwards  +44 (0)117 9400 636 *
* Critical Site Builderhttp://www.criticaldistribution.com *
* online collaborative web authoring content management system *
* i-Contact Progressive Video  http://www.videonetwork.org *
* Smashing the Corporate image   http://www.subvertise.org *
* Bristol Indymedia   http://bristol.indymedia.org *
* Bristol's radical news http://www.bristle.org.uk *
* PGP : F0CA 42B8 D56F 28AD 169B  49F3 3056 C6DB 8538 EEF8 *




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


RE: [PHP] mysql_fetch_array()

2002-04-05 Thread Phil Ewington

Jason,

This is for an events calendar, I want all the dates form the db but when I
am generating the individual days for the calendar I need to know whether
there is an event for that day, hence pulling out all the dates from the db.
As I am looping through all the days in a month to dynamically create the
calendar, I do not want to loop through the entire recordset to look for a
date for that day in each iteration. Does your method find any row in the
recordset with a given date?

I am at present exploring the possibility of creating individual arrays for
each row in the recordset using the date as the name of the array, then
testing to see if it exists. That way I can check for the existence of a
given date at any point in my code and reference the associated values
without looping through the recordset each time. My code is as follows...

while ($row = mysql_fetch_assoc($events)) {
$a = date_ . $row[event_date];
$$a = array($row[event_id], $row[event_title]);
}

if ($date_2002-04-15) { do_something(); }

Any comments will be greatfully received.

Phil.

 -Original Message-
 From: Jason Wong [mailto:[EMAIL PROTECTED]]
 Sent: 05 April 2002 11:31
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] mysql_fetch_array()


 On Friday 05 April 2002 18:21, you wrote:
  Hi All,
 
  I am new to PHP and am having a bit of trouble. I have a
 recordset using...
 
  $events = mysql_fetch_array($recordset);
 
  this drags in 3 columns from my table...
 
  event_id, event_title, event_date
 
  I want to search the recordset for a given date, if found I
 want to be able
  to reference event_id  event_title from the row. I am using PHP 4.01.

 Shouldn't you be doing your searching and selecting from within
 your mysql
 query?

 But if you insist on doing it in PHP then:


 if ($events['event_date'] == whatever) {
   do_something();
 }



 --
 Jason Wong - Gremlins Associates - www.gremlins.com.hk

 /*
 You will engage in a profitable business activity.
 */



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




RE: [PHP] mysql_fetch_array()

2002-04-05 Thread heinisch

At 05.04.2002  12:31, you wrote:

Jason,

This is for an events calendar, I want all the dates form the db but when I
am generating the individual days for the calendar I need to know whether
there is an event for that day, hence pulling out all the dates from the db.
As I am looping through all the days in a month to dynamically create the
calendar, I do not want to loop through the entire recordset to look for a
date for that day in each iteration. Does your method find any row in the
recordset with a given date?

As I understand your problem, I would suggest, that you just select the days
in the month, where there are events
f.e. select count(ref#) from DB where date 'inside your scope' and events 
'are there events'
this gives you the number of lines.
If there are any, you could ask more detailed, using the informations stored.
If there are no events, make the calendar as normal.
Thats also a good explanation for the column ref# (autoincrement, unique)

Even you only have to deal with one select, and can order your result, so 
that it makes
you no pain showing them


I am at present exploring the possibility of creating individual arrays for
each row in the recordset using the date as the name of the array, then
testing to see if it exists. That way I can check for the existence of a
given date at any point in my code and reference the associated values
without looping through the recordset each time. My code is as follows...

while ($row = mysql_fetch_assoc($events)) {
 $a = date_ . $row[event_date];
 $$a = array($row[event_id], $row[event_title]);
}

Here the select could be
Assuming you have the DB´s 'event_ref ' where 'event date' and 'event 
reference number' put in
and 'event_content' where other useful informations are stored
selct a.event_title, from event_ref a, event_content b where b.ref = a.ref 
and a.date='2002-04-15'
No dealing with arrays and var_vars, just straight sql.

HTH Oliver

if ($date_2002-04-15) { do_something(); }

Any comments will be greatfully received.


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




RE: [PHP] mysql_fetch_array()

2002-04-05 Thread Miguel Cruz

On Fri, 5 Apr 2002, Phil Ewington wrote:
 This is for an events calendar, I want all the dates form the db but when I
 am generating the individual days for the calendar I need to know whether
 there is an event for that day, hence pulling out all the dates from the db.
 As I am looping through all the days in a month to dynamically create the
 calendar, I do not want to loop through the entire recordset to look for a
 date for that day in each iteration.

That sounds like a lot of work (both for you and for the server). Assuming
you want to draw a monthly calendar where each day appears whether or not
it holds any events (it's even easier if you don't need that)...

Just make sure the database returns your results in date order.

   SELECT eventtitle, eventdate FROM event WHERE eventdate='2002-03-01' 
  AND eventdate'2002-04-01' ORDER BY eventdate

Then loop through the days and draw any events that happen to occur on 
each day as you get to it:

  $row = mysql_fetch_assoc($sql);
  for ($day = 1; $day = $num_days_in_month; $day++)
  {
 print h3$day/h3;
 while ($row  (date('j', strtotime($row['eventdate'])) == $day))
 {
print p{$row['eventtitle']}/p;
$row = mysql_fetch_assoc($sql);
 }
  }

miguel


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




Re: [PHP] mysql_fetch_array

2001-12-31 Thread Vincent Stoessel

you can also do

$queryString = select table1.uid as 'my_uid'  , table2.uid as 'their_uid'
from table1, table2
where ... ;






Greg Sidelinger wrote:

 
 
 
 Subject:
 
 [PHP] mysql_fetch_array
 From:
 
 Greg Sidelinger [EMAIL PROTECTED]
 Date:
 
 Sun, 30 Dec 2001 18:44:44 -0500
 To:
 
 [EMAIL PROTECTED]
 
 To:
 
 [EMAIL PROTECTED]
 
 
 Ok I have use mysql_fetch_array to dump the results of a select query with a
 join in it.
 if my tables contain a column with the same name how can I distinguish from
 them.  I'm used to
 table_name.value method in other languages but when I tried
 $row['table_name.value'] I don't get any values.
 can anyone point me in the right direction.
 
 
 
 



-- 
Vincent Stoessel [EMAIL PROTECTED]
Java Linux Apache Mysql Php (JLAMP) Engineer
(301) 362-1750 Mobile (410) 419-8588
AIM, MSN: xaymaca2020 , Yahoo Messenger: vks_jamaica


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] mysql_fetch_array

2001-12-30 Thread Greg Sidelinger

Ok I have use mysql_fetch_array to dump the results of a select query with a
join in it.
if my tables contain a column with the same name how can I distinguish from
them.  I'm used to
table_name.value method in other languages but when I tried
$row['table_name.value'] I don't get any values.
can anyone point me in the right direction.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_fetch_array

2001-12-30 Thread Bogdan Stancescu

If everything else fails, you should consider using mysql_fetch_row() instead.

Bogdan

Greg Sidelinger wrote:

 Ok I have use mysql_fetch_array to dump the results of a select query with a
 join in it.
 if my tables contain a column with the same name how can I distinguish from
 them.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_fetch_array

2001-12-30 Thread Mehmet Kamil ERISEN


 Hi,
In your SQL, you can say
select t1.col colt1, t2.col colt2
from table1 t1, table2 t2
where t1.something = t2.samething
In other words, you can name your columns differently in your select clause.
I
  Bogdan Stancescu [EMAIL PROTECTED] wrote: If everything else fails, you should consider 
using mysql_fetch_row() instead.

Bogdan

Greg Sidelinger wrote:

 Ok I have use mysql_fetch_array to dump the results of a select query with a
 join in it.
 if my tables contain a column with the same name how can I distinguish from
 them.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


Mehmet Erisen
http://www.erisen.com


-
Do You Yahoo!?
Send your FREE holiday greetings online at Yahoo! Greetings.


Re: [PHP] mysql_fetch_array() doesn't work

2001-09-27 Thread Jason G.


echo a href='$PHP_SELF?offset=$i*$step' target='_top'

Missing end quote and semicolon on this line may be the reason...

Try properly indenting and formatting your code.  Also take advantage of 
going in and out of php mode to seperate your code from your display of 
content...
Ex:
instead of this:
? echo(td align=\center\ width=\$nWidth\$sContent/td); ?
Try this:
td align=center width=? echo($nWidth); ?? echo($sContent); ?/td
Or even this:
td align=center width=?=$nWidth??=$sContent?/td

It makes it MUCH easier to read and maintain, and seperates the PHP code 
from the HTML content as much as possible.

Any questions, please ask me.

-Jason Garber
Lead Programmer - www.pulseaday.com
[EMAIL PROTECTED]

---

At 12:48 PM 9/27/2001 +0800, you wrote:
System: PHP4.06 + Mysql3.23.41 Win32 + Apache 1.3.20 Win32 + Win98

When PHP is running at the line: $arr=mysql_fetch_array($res);
The IE always show info as below:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or
`T_NUM_STRING' in c:\program files\apache
group\apache\htdocs\web\site1\list.php on line --[the number of line]

What's the problem wiht mysql_fetch_array() or other?
What does the T_STRING' or `T_VARIABLE' or `T_NUM_STRING' mean?

THANKS
Mike


The full code below:


?
$link=mysql_connect(localhost,,);
if($link==false){
echo Failed linking to database.;
exit();
}
$handler=mysql_select_db(database1);
if($handler==false)
echo Failed linking to database.;
$query=selct count(*) from users where sign=1;
$res=mysql_query($query);
$row=mysql_fetch_row($res);
$all=$row[0];
$step=5;
$pages=ceil($all/$step);   /*the number of pages needed to listed */
if(empty($offset))
$offset=0;
$query=select user_id, user_name, time, status, comment from users
where sign=1
order by user_name
limit $offset, $step;
$res=mysql_query($query);
echo tabletd align=centerUser/td
td align=centerAdded time/tdtd align=centerStatus/td/tr;
$num=mysql_num_rows($res);
for($i=0; $i$num; $i++) {
$arr=mysql_fetch_array($res);   /* HERE is line where the error occurs!!!
*/
echo trtd align=centera href=\profile.php?id=$arr['user_id']\
target='_top'
$arr['user_name']/a/td;
echo td align=center$arr['time']/td;
echo td align=center$arr['status']/td/tr;
echo tr colspan=3td$arr['comment']/td/tr;
}

echo /tablebrbrbr;

echo tabletrtd align='center';  /* show others in multi-pages */
for($i=0; $i$pages; $i++){
echo a href='$PHP_SELF?offset=$i*$step' target='_top'
echo ($i+1)./a;
echo nbsp;nbsp;;
}
echo /td/tr/table;

?


-
create table users (
user_id int not null auto_increment primary key,
user_name varchar(30),
time datetime,
status tinyint(1),
comment text,
sign tinyint(1) default '1'
);







-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



Re: [PHP] mysql_fetch_array() doesn't work

2001-09-27 Thread Naintara Jain

Hi Mike,

The query
$query=selct count(*) from users where sign=1;
should be select not selct

-and in future to know if there is any error in your queries you might want to check 
this way:
if(mysql_query($query)
{
--do statements--
}
else
-error msg-

or even the following would be a convenient way to get your recordset and check for 
invalid query.
just try this

$result = mysql_query (SELECT my_col FROM my_tbl)
or die (Invalid query);
  
IN YOUR CASE try:
$res=mysql_query($query) or die (Invalid query);

and let me know if you still have a problem.

-Naintara




- Original Message - 
From: Web user [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, September 27, 2001 10:18 AM
Subject: [PHP] mysql_fetch_array() doesn't work


System: PHP4.06 + Mysql3.23.41 Win32 + Apache 1.3.20 Win32 + Win98

When PHP is running at the line: $arr=mysql_fetch_array($res);
The IE always show info as below:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or
`T_NUM_STRING' in c:\program files\apache
group\apache\htdocs\web\site1\list.php on line --[the number of line]

What's the problem wiht mysql_fetch_array() or other?
What does the T_STRING' or `T_VARIABLE' or `T_NUM_STRING' mean?

THANKS
Mike


The full code below:


?
$link=mysql_connect(localhost,,);
if($link==false){
echo Failed linking to database.;
exit();
}
$handler=mysql_select_db(database1);
if($handler==false)
echo Failed linking to database.;
$query=selct count(*) from users where sign=1;
$res=mysql_query($query);
$row=mysql_fetch_row($res);
$all=$row[0];
$step=5;
$pages=ceil($all/$step);   /*the number of pages needed to listed */
if(empty($offset))
$offset=0;
$query=select user_id, user_name, time, status, comment from users
where sign=1
order by user_name
limit $offset, $step;
$res=mysql_query($query);
echo tabletd align=centerUser/td
td align=centerAdded time/tdtd align=centerStatus/td/tr;
$num=mysql_num_rows($res);
for($i=0; $i$num; $i++) {
$arr=mysql_fetch_array($res);   /* HERE is line where the error occurs!!!
*/
echo trtd align=centera href=\profile.php?id=$arr['user_id']\
target='_top'
$arr['user_name']/a/td;
echo td align=center$arr['time']/td;
echo td align=center$arr['status']/td/tr;
echo tr colspan=3td$arr['comment']/td/tr;
}

echo /tablebrbrbr;

echo tabletrtd align='center';  /* show others in multi-pages */
for($i=0; $i$pages; $i++){
echo a href='$PHP_SELF?offset=$i*$step' target='_top'
echo ($i+1)./a;
echo nbsp;nbsp;;
}
echo /td/tr/table;

?


-
create table users (
user_id int not null auto_increment primary key,
user_name varchar(30),
time datetime,
status tinyint(1),
comment text,
sign tinyint(1) default '1'
);







-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] mysql_fetch_array() doesn't work

2001-09-26 Thread Web user

System: PHP4.06 + Mysql3.23.41 Win32 + Apache 1.3.20 Win32 + Win98

When PHP is running at the line: $arr=mysql_fetch_array($res);
The IE always show info as below:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or
`T_NUM_STRING' in c:\program files\apache
group\apache\htdocs\web\site1\list.php on line --[the number of line]

What's the problem wiht mysql_fetch_array() or other?
What does the T_STRING' or `T_VARIABLE' or `T_NUM_STRING' mean?

THANKS
Mike


The full code below:


?
$link=mysql_connect(localhost,,);
if($link==false){
echo Failed linking to database.;
exit();
}
$handler=mysql_select_db(database1);
if($handler==false)
echo Failed linking to database.;
$query=selct count(*) from users where sign=1;
$res=mysql_query($query);
$row=mysql_fetch_row($res);
$all=$row[0];
$step=5;
$pages=ceil($all/$step);   /*the number of pages needed to listed */
if(empty($offset))
$offset=0;
$query=select user_id, user_name, time, status, comment from users
where sign=1
order by user_name
limit $offset, $step;
$res=mysql_query($query);
echo tabletd align=centerUser/td
td align=centerAdded time/tdtd align=centerStatus/td/tr;
$num=mysql_num_rows($res);
for($i=0; $i$num; $i++) {
$arr=mysql_fetch_array($res);   /* HERE is line where the error occurs!!!
*/
echo trtd align=centera href=\profile.php?id=$arr['user_id']\
target='_top'
$arr['user_name']/a/td;
echo td align=center$arr['time']/td;
echo td align=center$arr['status']/td/tr;
echo tr colspan=3td$arr['comment']/td/tr;
}

echo /tablebrbrbr;

echo tabletrtd align='center';  /* show others in multi-pages */
for($i=0; $i$pages; $i++){
echo a href='$PHP_SELF?offset=$i*$step' target='_top'
echo ($i+1)./a;
echo nbsp;nbsp;;
}
echo /td/tr/table;

?


-
create table users (
user_id int not null auto_increment primary key,
user_name varchar(30),
time datetime,
status tinyint(1),
comment text,
sign tinyint(1) default '1'
);







-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_fetch_array() doesn't work

2001-09-26 Thread Philip Olson

hi.  this doesn't have to do with mysql_fetch_array.  the following will
create that error :

  echo a $b['c'] d e f;

the following will not :

  echo a $b[c] d e {$f['g']} h i $j[$k] l 'm' n o p;

adjust accordingly.  just posted a few words on this topic recently, can
view them here :

  http://marc.theaimsgroup.com/?l=php-generalm=100152166602273

regards,
Philip Olson


On Thu, 27 Sep 2001, Web user wrote:

 System: PHP4.06 + Mysql3.23.41 Win32 + Apache 1.3.20 Win32 + Win98
 
 When PHP is running at the line: $arr=mysql_fetch_array($res);
 The IE always show info as below:
 Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or
 `T_NUM_STRING' in c:\program files\apache
 group\apache\htdocs\web\site1\list.php on line --[the number of line]
 
 What's the problem wiht mysql_fetch_array() or other?
 What does the T_STRING' or `T_VARIABLE' or `T_NUM_STRING' mean?
 
 THANKS
 Mike
 
 
 The full code below:
 
 
 ?
 $link=mysql_connect(localhost,,);
 if($link==false){
 echo Failed linking to database.;
 exit();
 }
 $handler=mysql_select_db(database1);
 if($handler==false)
 echo Failed linking to database.;
 $query=selct count(*) from users where sign=1;
 $res=mysql_query($query);
 $row=mysql_fetch_row($res);
 $all=$row[0];
 $step=5;
 $pages=ceil($all/$step);   /*the number of pages needed to listed */
 if(empty($offset))
 $offset=0;
 $query=select user_id, user_name, time, status, comment from users
 where sign=1
 order by user_name
 limit $offset, $step;
 $res=mysql_query($query);
 echo tabletd align=centerUser/td
 td align=centerAdded time/tdtd align=centerStatus/td/tr;
 $num=mysql_num_rows($res);
 for($i=0; $i$num; $i++) {
 $arr=mysql_fetch_array($res);   /* HERE is line where the error occurs!!!
 */
 echo trtd align=centera href=\profile.php?id=$arr['user_id']\
 target='_top'
 $arr['user_name']/a/td;
 echo td align=center$arr['time']/td;
 echo td align=center$arr['status']/td/tr;
 echo tr colspan=3td$arr['comment']/td/tr;
 }
 
 echo /tablebrbrbr;
 
 echo tabletrtd align='center';  /* show others in multi-pages */
 for($i=0; $i$pages; $i++){
 echo a href='$PHP_SELF?offset=$i*$step' target='_top'
 echo ($i+1)./a;
 echo nbsp;nbsp;;
 }
 echo /td/tr/table;
 
 ?
 
 
 -
 create table users (
 user_id int not null auto_increment primary key,
 user_name varchar(30),
 time datetime,
 status tinyint(1),
 comment text,
 sign tinyint(1) default '1'
 );
 
 
 
 
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] mysql_fetch_array() doesn't work

2001-09-25 Thread Web user

System: PHP4.06 + Mysql3.23.41 Win32 + Apache 1.3.20 Win32 + Win98


?
..
..
$res=mysql_query($query);
$num=mysql_num_rows($res);
for($i=0; $i$num; $i++){
$arr=mysql_fetch_array($res);
...
}
...

When PHP is running at the line: $arr=mysql_fetch_array($res);
The IE always show info as below:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or
`T_NUM_STRING' in
c:\program files\apache group\apache\...\page.php on line ...

What's the problem wiht mysql_fetch_array() or other?

Thanks!
Mike







-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] mysql_fetch_array

2001-09-06 Thread nate

Can someone tell me what i'm doing wrong here?

?php
 //Connect to db
 $db = mysql_pconnect(localhost,login,pass);
 mysql_select_db(database,$db);

 //Check for the IP
 $result2 = mysql_query(SELECT ip FROM ip where ip = '$REMOTE_ADDR',$db);

while($myrowmysql_fetch_array($result2))
 {
echo Print some text here!;
 }
?

Basically I just want to print text if the IP address was not found in the database, 
and if it was found then I want to print Print some text here!

Please help!
Thanks,
Nate



Re: [PHP] mysql_fetch_array

2001-09-06 Thread David Robley

On Thu,  6 Sep 2001 18:09, [EMAIL PROTECTED] wrote:
 Can someone tell me what i'm doing wrong here?

 ?php
  //Connect to db
  $db = mysql_pconnect(localhost,login,pass);
  mysql_select_db(database,$db);

  //Check for the IP
  $result2 = mysql_query(SELECT ip FROM ip where ip =
 '$REMOTE_ADDR',$db);

 while($myrowmysql_fetch_array($result2))
  {
 echo Print some text here!;
  }
 ?

 Basically I just want to print text if the IP address was not found in
 the database, and if it was found then I want to print Print some text
 here!

 Please help!
 Thanks,
 Nate

I think it would make more sense to check the number of rows found, and 
act accordingly. If you don't need to use any of the info from the DB, 
you could do a SELECT COUNT(ip) WHERE 

Alternatively, test mysql_num_rows($result2).


-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   He who laughs last probably made a backup.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_fetch_array

2001-09-06 Thread sagar

hi,
just go thru ur code once u'll getout with the bug.

$myrowmysql_fetch_Array($result2);

what is $myrow and to which value should the left part should
compare.

try this :
?php
 file://Connect to db
 $db = mysql_pconnect(localhost,login,pass);
 mysql_select_db(database,$db);

 file://Check for the IP
 $result2 = mysql_query(SELECT ip FROM ip where ip = '$REMOTE_ADDR',$db);
$myrow=mysql_fetch_Array($result2);
if($myrow)
  //  if there is a record then the code goes here
else
  echo(print some text here);
?

/sagar


- Original Message -
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, September 06, 2001 2:09 PM
Subject: [PHP] mysql_fetch_array


Can someone tell me what i'm doing wrong here?

?php
 file://Connect to db
 $db = mysql_pconnect(localhost,login,pass);
 mysql_select_db(database,$db);

 file://Check for the IP
 $result2 = mysql_query(SELECT ip FROM ip where ip = '$REMOTE_ADDR',$db);

while($myrowmysql_fetch_array($result2))
 {
echo Print some text here!;
 }
?

Basically I just want to print text if the IP address was not found in the
database, and if it was found then I want to print Print some text here!

Please help!
Thanks,
Nate



_
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] mySql_fetch_array($result) question.

2001-08-21 Thread ERISEN, Mehmet Kamil

Hello All,
Another question.
Here is the problem: 
- One SQL query 
- 1 result.

I have a form that has more than one drop down lists.  I
like to use the mysql_fetch_array($result) to populate the
select options.
The problem is that after the first use, the
mysql_fetch_array($result) does not return anything.

Any suggestion.

note: As a workaround, I am running the select statement
(The SQL) 10 time. I think it's not a good solution
though!!

Thanks,
Mehmet.

=
Mehmet Erisen
http://www.erisen.com

__
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] mysql_fetch_array()

2001-03-07 Thread Deependra B. Tandukar

Greetings!

I am using PHP and MySQL in RedHat 6.0.
I have used mysql_fetch_array() to display the datas in web page but all the
columns are printed twice. What can be the wrong with my code:
?php
$connection=mysql_connection(...);
$db=mysql_select_db(.);
$sql="select * from my db";
$sql_result=$mysql_query($sql,$connection);
print "table";
while ($row=mysql_fetch_array($sql_result))
{
print "tr";
foreach ($row as $field)
print "td$field/td";
print "tda href=\"search.php?ID=$row[ID]\"";
print "Get it";
print "/a/td";
print "/tr";
}
print "/table";
?

But it works fine with mysql_fetch_row() however it does not pass the pass
the variable ID.

Looking forward to hearing from you.

Warm regards,
DT






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] mysql_fetch_array()

2001-03-07 Thread Tyler Longren

?php
$connection=mysql_connection(...);
$db=mysql_select_db(.);
$sql="select * from my db";
$sql_result=mysql_query($sql,$connection);
print "table";
while ($row=mysql_fetch_array($sql_result))
{
print "tr";
foreach ($row as $field)
print "td$field/td";
print "tda href=\"search.php?ID=$row[ID]\"";
print "Get it";
print "/a/td";
print "/tr";
}
print "/table";
?

Try that, you tried to call $mysql_query, when you needed to call
mysql_query.  In your code, $mysql_query isn't a variable, it's a function
in PHP.
-Original Message-
From: Deependra B. Tandukar [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 07, 2001 9:34 PM
To: [EMAIL PROTECTED]
Subject: [PHP] mysql_fetch_array()


Greetings!

I am using PHP and MySQL in RedHat 6.0.
I have used mysql_fetch_array() to display the datas in web page but all the
columns are printed twice. What can be the wrong with my code:
?php
$connection=mysql_connection(...);
$db=mysql_select_db(.);
$sql="select * from my db";
$sql_result=$mysql_query($sql,$connection);
print "table";
while ($row=mysql_fetch_array($sql_result))
{
print "tr";
foreach ($row as $field)
print "td$field/td";
print "tda href=\"search.php?ID=$row[ID]\"";
print "Get it";
print "/a/td";
print "/tr";
}
print "/table";
?

But it works fine with mysql_fetch_row() however it does not pass the pass
the variable ID.

Looking forward to hearing from you.

Warm regards,
DT






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_fetch_array()

2001-03-07 Thread David Robley

On Thu,  8 Mar 2001 14:03, Deependra B. Tandukar wrote:
 Greetings!

 I am using PHP and MySQL in RedHat 6.0.
 I have used mysql_fetch_array() to display the datas in web page but
 all the columns are printed twice. What can be the wrong with my code:
 ?php
 $connection=mysql_connection(...);
 $db=mysql_select_db(.);
 $sql="select * from my db";
 $sql_result=$mysql_query($sql,$connection);
 print "table";
 while ($row=mysql_fetch_array($sql_result))
 {
 print "tr";
 foreach ($row as $field)
 print "td$field/td";
 print "tda href=\"search.php?ID=$row[ID]\"";
 print "Get it";
 print "/a/td";
 print "/tr";
 }
 print "/table";
 ?

 But it works fine with mysql_fetch_row() however it does not pass the
 pass the variable ID.

 Looking forward to hearing from you.

 Warm regards,

First up, shouldn't you have {} to delineate what is actually the foreach 
procedure(s)?

I would suggest using extract within your While loop to make the table 
fields available as variables.

while ($row=mysql_fetch_array($sql_result))
  {
  extract($row);
  echo "tr";
  echo "td$field/td"; \\ or whatever the field is called
  echo "tda href=\"search.php?ID=$ID\"";
  echo "Get it";
  echo "/a/td";
  echo "/tr";
  }


-- 
David Robley| WEBMASTER  Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES  | http://www.nisu.flinders.edu.au/
AusEinet| http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] mysql_fetch_array and row referencing under 4.0.4pl1

2001-02-12 Thread Scott Brown

Have I lost something somewhere?

I have code which runs under PHP3.0.15, and PHP4.0.2 which references the
result of a

$row = mysql_fetch_array($result_of_query);

by doing things like:

$row["this_is_a_field_name"]

Seems simple, right?

Well - I compiled a new copy of Apache 1.3.17, pushed PHP up to 4.0.4pl1,
and upgraded mysql to the new stable version at the same time...

Now the above code doesnt work.  But if I do a:

$row[this_is_a_field_name]

Then the code does work.

Have I messed up something in the PHP configuration that doesnt allow these
quoted identifiers anymore?

Or is this just a new (less-than-compatible) upgrade to PHP that I've missed
reading about??

Heelp me ... I dont want to have to rebuild all my sites
just because of these stupid quotes





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_fetch_array and row referencing under 4.0.4pl1

2001-02-12 Thread Thomas Deliduka

I'd be curious to see others' answers on this because I upgraded everything
the other day (been at php4 for a while though) and I don't have a problem
with the quotes.

On 2/12/01 11:11 PM this was written:

 Have I lost something somewhere?
 
 I have code which runs under PHP3.0.15, and PHP4.0.2 which references the
 result of a
 
 $row = mysql_fetch_array($result_of_query);
 
 by doing things like:
 
 $row["this_is_a_field_name"]
 
 Seems simple, right?
 
 Well - I compiled a new copy of Apache 1.3.17, pushed PHP up to 4.0.4pl1,
 and upgraded mysql to the new stable version at the same time...
 
 Now the above code doesnt work.  But if I do a:
 
 $row[this_is_a_field_name]
 
 Then the code does work.
 
 Have I messed up something in the PHP configuration that doesnt allow these
 quoted identifiers anymore?
 
 Or is this just a new (less-than-compatible) upgrade to PHP that I've missed
 reading about??
 
 Heelp me ... I dont want to have to rebuild all my sites
 just because of these stupid quotes
 

-- 

Thomas Deliduka
IT Manager
 -
New Eve Media
The Solution To Your Internet Angst
http://www.neweve.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_fetch_array and row referencing under 4.0.4pl1

2001-02-12 Thread Steve Werby

"Scott Brown" [EMAIL PROTECTED] wrote:
 I have code which runs under PHP3.0.15, and PHP4.0.2 which references the
 result of a
 $row["this_is_a_field_name"]

 Well - I compiled a new copy of Apache 1.3.17, pushed PHP up to 4.0.4pl1,
 and upgraded mysql to the new stable version at the same time...

 Now the above code doesnt work.  But if I do a:

What error messages do you get?  Add this to beginning of your code and you
might get more error output that will help diagnose.

?php error_reporting(E_ALL); ?

 $row[this_is_a_field_name]

 Then the code does work.

Odd.  I've noticed the non-quoted versions causing PHP to choke if
error_reporting() is set high enough.  I've never know the opposite to be
true.

 Have I messed up something in the PHP configuration that doesnt allow
these
 quoted identifiers anymore?

 Or is this just a new (less-than-compatible) upgrade to PHP that I've
missed
 reading about??

It could be a configuration option or a php.ini setting.  Create a page with
?php phpinfo(); ? in it and post your configuration options to the list.

--
Steve Werby
COO
24-7 Computer Services, LLC
Tel: 804.817.2470
http://www.247computing.com/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_fetch_array and row referencing under 4.0.4pl1

2001-02-12 Thread Steve Werby

"Scott Brown" [EMAIL PROTECTED] wrote:
 $row["this_is_a_field_name"]

 Seems simple, right?

 Well - I compiled a new copy of Apache 1.3.17, pushed PHP up to 4.0.4pl1,
 and upgraded mysql to the new stable version at the same time...

 Now the above code doesnt work.  But if I do a:

Forgot to ask - does referencing an array with double quotes around the key
work for arrays not associated with a MySQL result?  I doubt it's specific
to MySQL result arrays, but it doesn't hurt to check.  Make a small array
and test.

--
Steve Werby
COO
24-7 Computer Services, LLC
Tel: 804.817.2470
http://www.247computing.com/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] mysql_fetch_array and row referencing under 4.0.4pl1

2001-02-12 Thread Scott Brown



 Forgot to ask - does referencing an array with double quotes
 around the key work for arrays not associated with a MySQL
 result?  I doubt it's specific to MySQL result arrays, but
 it doesn't hurt to check.  Make a small array and test.

I grabbed an example of of php.net dealing with just arrays and it works ...

Here's what I'm seeing - THIS WORKS:

HTML
HEAD
TITLEmysqltest/TITLE
/HEAD
BODY BGCOLOR="#FF"
?
require($DOCUMENT_ROOT . "/subs/sub.php");

openDSN();

echo "table\n";
$rslt = mysql_query("select * from pricing");
while ( $row = mysql_fetch_array($rslt) )
{
echo "TR\n";
echo "TD$row[ID]/tD";
echo "TD$row[ProdCode]/tD";
echo "TD$row[Price_effdate]/tD";
echo "TD$row[ProdSetup]/tD";
echo "TD$row[ProdMonthly]/tD";
echo "TD$row[5]/tD";
echo "/TR\n";
}
echo "/table\n";
?
/BODY
/HTML


But put any one of these $row[...] with quotes around their fieldnames and I
get:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or
`T_NUM_STRING' in /home/testnexus/public_html/test.php on line 16

(when line 16 =
echo "TD$row["ID"]/tD";
)


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] mysql_fetch_array and row referencing under 4.0.4pl1

2001-02-12 Thread Scott Brown




 I'd be curious to see others' answers on this because I
 upgraded everything
 the other day (been at php4 for a while though) and I don't
 have a problem
 with the quotes.


I've probably just putzed something somewhere during the build  it's
been one of those days.

But the thing is it's consistant... if I quote my field names (single or
double) I get an error... if I dont, I get my result.

(see my response to Steve...)


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_fetch_array strangeness

2001-01-24 Thread Markus Fischer


Because, basically, in php an array is a hash with just numbers
as keys.

m.

-- 
Markus Fischer,  http://josefine.ben.tuwien.ac.at/~mfischer/
EMail: [EMAIL PROTECTED]
PGP Public  Key: http://josefine.ben.tuwien.ac.at/~mfischer/C2272BD0.asc
PGP Fingerprint: D3B0 DD4F E12B F911 3CE1  C2B5 D674 B445 C227 2BD0

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] mysql_fetch_array strangeness

2001-01-21 Thread Jaxon

Hi,

I'm trying to echo out the field names used as key values in a
mysql_fetch_array:

$link_id = mysql_connect("localhost", "root", $pass);

mysql_select_db("database", $link_id);

$result = mysql_query("select * from lists where id = 1", $link_id);

$rowData = mysql_fetch_array($result);

while (list($fieldName) = each($rowData))
{ echo "$fieldName,"; }

I'm expecting to get this:

id,listname,joinconfirm,leaveconfirm,homepage,author,canjoin,bannedemails,de
scription,subject,masteremail,

but instead getting this:

0,id,1,listname,2,joinconfirm,3,leaveconfirm,4,homepage,5,author,6,canjoin,7
,bannedemails,8,description,9,subject,10,masteremail,

Why are the index numbers for the array showing up?  From the docs,
mysql_fetch_array should create an array of field names to field values...?
To make things worse, if I also echo the data:

while (list($fieldName,  $fieldValue) = each($rowData))
{ echo "$fieldName,$fieldValue," ;}

Then a value is echoed after both the index number and the field value, eg:

0,1,id,1,1,testlist,listname,testlist,  etc...

What am I doing wrong?

Regards,
Jaxon


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_fetch_array strangeness

2001-01-21 Thread Kristi Russell

each() assigns four elements... (0 = index), (1 = value), (key = index), (value = 
value)

You are concerned with key and value.
So: list ($fieldname, $value) = each($row)

You may not be using $value but you still need to assign the data to a variable. Or 
list will only assign $fieldname the numerical
index and not the char index. At least that's from what I understand.  Anyone, please 
feel free to correct me.

Kristi


Beware of the false gods we sometimes
worship--money, power and fame--for they
are all fleeting, especially in death and often
in mortality.
   -Anonymous

- Original Message -
From: "Jaxon" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Sunday, January 21, 2001 8:07 PM
Subject: [PHP] mysql_fetch_array strangeness


 Hi,

 I'm trying to echo out the field names used as key values in a
 mysql_fetch_array:

 $link_id = mysql_connect("localhost", "root", $pass);

 mysql_select_db("database", $link_id);

 $result = mysql_query("select * from lists where id = 1", $link_id);

 $rowData = mysql_fetch_array($result);

 while (list($fieldName) = each($rowData))
 { echo "$fieldName,"; }

 I'm expecting to get this:

 id,listname,joinconfirm,leaveconfirm,homepage,author,canjoin,bannedemails,de
 scription,subject,masteremail,

 but instead getting this:

 0,id,1,listname,2,joinconfirm,3,leaveconfirm,4,homepage,5,author,6,canjoin,7
 ,bannedemails,8,description,9,subject,10,masteremail,

 Why are the index numbers for the array showing up?  From the docs,
 mysql_fetch_array should create an array of field names to field values...?
 To make things worse, if I also echo the data:

 while (list($fieldName,  $fieldValue) = each($rowData))
 { echo "$fieldName,$fieldValue," ;}

 Then a value is echoed after both the index number and the field value, eg:

 0,1,id,1,1,testlist,listname,testlist,  etc...

 What am I doing wrong?

 Regards,
 Jaxon


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]