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

2011-10-28 Thread Paul Halliday
On Fri, Oct 28, 2011 at 7:19 PM, Daniel Brown danbr...@php.net 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().

    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/


Sorry.

I was just throwing it out there with the hope that there might be a
tidbit that would help the OP.

I have a simliar setup and I can query far more than a 1/4 million
rows. What I offered is what I am doing differently.


-- 
Paul Halliday
http://www.squertproject.org/

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



[PHP] Re: mysql_fetch_array

2007-11-03 Thread M. Sokolewicz

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 


Are you sure your query is returning  1 row ? Because from the looks of 
the code you posted it should do exactly what you expect it to.


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



[PHP] Re: mysql_fetch_array()

2004-08-17 Thread Hannes Magnusson
On Tue, 17 Aug 2004 18:18:24 -0400
[EMAIL PROTECTED] (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?
php.net/mysql_fetch_array
array mysql_fetch_array ( resource result [, int result_type])
meaning; no. You don't need to specify the second argumen.

 
 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] Re: mysql_fetch_array()

2004-08-17 Thread Matthew Sims
 On Tue, 17 Aug 2004 18:18:24 -0400
 [EMAIL PROTECTED] (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?
 php.net/mysql_fetch_array
 array mysql_fetch_array ( resource result [, int result_type])
 meaning; no. You don't need to specify the second argumen.


 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

As Tony shows, anything between the [] is optional.

-- 
--Matthew Sims
--http://killermookie.org

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



[PHP] Re: mysql_fetch_array problem

2002-08-11 Thread Bogdan Stancescu

Hi Jonni!

You should consider wrapping mysql_fetch_*() functions into a 
personalized function which also takes care of errors - at least for 
debugging. Your problem is typical - your query has some problems and 
mysql_run_query() returns a null result, which is indeed not a valid 
MySQL result resource. What you should do is to run something like

$result=mysql_run_query(your SQL here);
if (!$result) {
   echo(BMySQL query error in query /BI.
 your SQL here./IBR /\n);
   echo(mysql_error());
}

and debug the SQL. Now that's tedious to write for every, and that's why 
I was suggesting wrapping the thing into a function - but that's 
obviously not mandatory as long as you can debug it, right? :-)

Another idea while I'm on the topic, if you do create a wrapper, you may 
also consider sending yourself an e-mail if an error occurs after 
everything works right - that way you'll be able to track errors quickly 
- and impress your customers!

HTH

Bogdan

Jonni wrote:
 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
 
 


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




[PHP] Re: mysql_fetch_array()

2002-04-09 Thread David Anton

while( $row = mysql_fetch_array( $recordset ) ) {
  $var1 = $row[event_id] ;
  $var2 = $row[event_title] ;
  $var3 = $row[event_date] ;
}

Don't forget that what you get with mysql_fetch_array() is just a array
where the indexes are just the name of the columns.

Un saludo


Phil Ewington [EMAIL PROTECTED] schrieb im Newsbeitrag
000a01c1dc8b$a8d7e2d0$bdff0350@lithium">news:000a01c1dc8b$a8d7e2d0$bdff0350@lithium...
 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




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

2001-09-30 Thread Web user

Hello,
First, Thank you all for your help!
I  finally found the reason for why does  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]

It is because the echo (including print) doesn't work at the line below,
echo trtda href=\profile.php?id=$arr['user_id']\  target='_top';
showing the error info as I mentioned. ( but it should work according to PHP
books)

It only works when  the $arr['user_id'] is out of the quotes.
echo trtda href=\profile.php?id=.$arr['user_id'].\
target='_top';
then IE showed no error any longer.

So I have to let all $arr['key']  out of the quotes, then the scripts are
Ok.

Regards
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] Re: mysql_fetch_array() doesn't work

2001-09-30 Thread Web user

Hello,
First, Thank you all for your help!
I  finally found the reason for why does  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]

It is because the echo (including print) doesn't work at the line
below,
echo trtda href=\profile.php?id=$arr['user_id']\  target='_top';
showing the error info as I mentioned. ( but it should work according to PHP
books)

It only works when  the $arr['user_id'] is out of the quotes.
echo trtda href=\profile.php?id=.$arr['user_id'].\
target='_top';
then IE showed no error any longer.

So I have to let all $arr['key']  out of the quotes, then the scripts are
Ok.

Regards
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] Re: mysql_fetch_array() doesn't work

2001-09-25 Thread Pedja


array mysql_fetch_row (resource result)

MySql_fetch_array returns an array that corresponds to the fetched row, or
FALSE if there are no more rows. So put MySql_fetch_array in FOR loop. Look
like this:
for ($count = 1; $row = mysql_fetch_row ($query_result_handle); ++$count)
{
...
}

...the same thing with WHILE:
a)
while ($row = mysql_fetch_row ($query_result_handle))
{ 
... 
} 
b)
while (list($first, $second) = mysql_fetch_row($resource)) { 
[...] 
}


Web User [EMAIL PROTECTED] wrote in message 
008601c1459e$5f853800$6a915fd3@hexiao">news:008601c1459e$5f853800$6a915fd3@hexiao...
 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] Re: mysql_fetch_array

2001-09-07 Thread Doug Granzow


[EMAIL PROTECTED] wrote in message
001001c136af$7c649db0$[EMAIL PROTECTED]">news:001001c136af$7c649db0$[EMAIL PROTECTED]...
Can someone tell me what i'm doing wrong here?

while($myrowmysql_fetch_array($result2))


I would guess that you actually want that line to read:

while($myrow=mysql_fetch_array($result2))


Doug Granzow
[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] Re: mySql_fetch_array($result) question.

2001-08-21 Thread CC Zona

In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] (Mehmet Kamil Erisen) wrote:

 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.

http://php.net/manual/en/function.mysql-data-seek.php

-- 
CC

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