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

Your name:

Reply:


Posted by Ninad on 12/17/64 11:55

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

[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

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