You are here: Re: Warning: mysql_fetch_array(): 5 is not a valid MySQL result resource « PHP Programming Language « IT news, forums, messages
Re: Warning: mysql_fetch_array(): 5 is not a valid MySQL result resource

Posted by Petr Vileta on 11/21/17 11:55

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

--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)



"Ninad" <ninadk@gmail.com> wrote in message
news:1155555463.961902.257090@i3g2000cwc.googlegroups.com...
> Hi Petr,
> in while loops condition you are fetching the next row each time
> when it fetch the 3rd row which is the last row and next time tries to
> fetch the row but it don't found any row so it returns the error at
> fetching the row you can fecht the rows inside the while loop not in
> while condition below could be one option
>
> function list_it($result)
> {
> $rows = mysql_num_rows($result);
> for ($i=0;$i<$rows;$i++)
> {
> $row = mysql_fetch_array($result, MYSQL_ASSOC)
> echo $row["id"], "<br>";
> }
> }
>
> Thanks
> Ninad
>
> Petr Vileta wrote:
>> Hi, I'm new here and excuse me if this question was be here earlier.
>>
>> I have a simple code
>>
>> <html><body>
>> <?php
>> <?php
>> $link = mysql_connect("localhost", "user", "password")
>> or die("Grr: " . mysql_error());
>> mysql_select_db("my_dbf") or die("Grr");
>> $query = "select id from my_table where id < 4 order by id";
>> $result = mysql_query($query) or die("Grr: " . mysql_error());
>> $rows = mysql_num_rows($result);
>> echo "Rows=", $rows, "<br>" ;
>> list_it($result);
>>
>> function list_it($result)
>> {
>> while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
>> {
>> echo $row["id"], "<br>";
>> }
>> }
>> ?>
>> </body></html>
>>
>> This code produce this 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 ...
>>
>> Why warning?
>> This is a simple example. In my real code I must use a few different
>> functions for displaing mysql_fetch_array() result and $query variable I
>> must create before any html output because I use sessions.
>> How to pass resource type variable into function as parameter?
>> Oh, my PHP version is 4.3.7 on Windoze ;-)
>>
>> --
>>
>> Petr Vileta, Czech republic
>> (My server rejects all messages from Yahoo and Hotmail. Send me your mail
>> from another non-spammer site please.)
>

 

Navigation:

[Reply to this 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

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