Reply to Re: Warning: mysql_fetch_array(): 5 is not a valid MySQL result resource

Your name:

Reply:


Posted by Rik on 09/30/79 11:55

Petr Vileta wrote:
> Hmm, curious ;-)
> I'm using while loop in all other cases without error or warning.
> With one exception - both
> mysql_query() and mysql_fetch_array() is in the same program block.
> If i try this
>
> $result = mysql_query($query)
> $rows = mysql_num_rows($result);
> while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
> {
> echo $row["id"], "<br>";
> }
>
> I don't get warning. But if I put while() into function, I will get.
> IMHO this is because $result is "resource" type variable. But how to
> pass this type variable to function? Maybe I temporary switch-off
> warnings in function :-)

Nope, a resource can be handles here perfectly. The following code produces
no errors:

<?php
function check($arg){
while($row = mysql_fetch_assoc($arg)){
print_r($row);
}
}
$link = mysql_connect('localhost','root');
mysql_select_db('testbase',$link);
$result = mysql_query('SELECT * FROM tbl_test');
check($result);
?>

Judging by your output:
>
> Rows=3
> 1
> 2
> 3
> Warning: mysql_fetch_array(): 5 is not a valid MySQL result resource
> in F:\webpub\php\test.php on line ...
>

Do the 1\n2\n3 mean these rows are shown? If yes, did you give us the entire
code? It would seem a _second_ fetch is performed on the result that we're
not aware of. Could you show us the entire relevant code?

Grtz,
--
Rik Wasmus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация