473,573 Members | 2,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Warning: mysql_fetch_arr ay(): 5 is not a valid MySQL result resource

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($qu ery) 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_arr ay($result, MYSQL_ASSOC))
{
echo $row["id"], "<br>";
}
}
?>
</body></html>

This code produce this output:

Rows=3
1
2
3
Warning: mysql_fetch_arr ay(): 5 is not a valid MySQL result resource in
F:\webpub\php\t est.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_arr ay() 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.)


Aug 14 '06 #1
9 7410
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_arr ay($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($qu ery) 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_arr ay($result, MYSQL_ASSOC))
{
echo $row["id"], "<br>";
}
}
?>
</body></html>

This code produce this output:

Rows=3
1
2
3
Warning: mysql_fetch_arr ay(): 5 is not a valid MySQL result resource in
F:\webpub\php\t est.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_arr ay() 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.)
Aug 14 '06 #2
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($qu ery) 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_arr ay($result, MYSQL_ASSOC))
{
echo $row["id"], "<br>";
}
}
?>
</body></html>

This code produce this output:

Rows=3
1
2
3
Warning: mysql_fetch_arr ay(): 5 is not a valid MySQL result resource in
F:\webpub\php\t est.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_arr ay() 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 ;-)
The code you showed should not display this error. Unfortunately, you
left out what's probably the most important piece - the line number of
the failing code.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 14 '06 #3
Hmm, curious ;-)
I'm using while loop in all other cases without error or warning. With one
exception - both
mysql_query() and mysql_fetch_arr ay() is in the same program block. If i
try this

$result = mysql_query($qu ery)
$rows = mysql_num_rows( $result);
while ($row = mysql_fetch_arr ay($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" <ni****@gmail.c omwrote in message
news:11******** **************@ i3g2000cwc.goog legroups.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_arr ay($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_d b("my_dbf") or die("Grr");
$query = "select id from my_table where id < 4 order by id";
$result = mysql_query($qu ery) or die("Grr: " . mysql_error());
$rows = mysql_num_rows( $result);
echo "Rows=", $rows, "<br>" ;
list_it($resul t);

function list_it($result )
{
while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC))
{
echo $row["id"], "<br>";
}
}
?>
</body></html>

This code produce this output:

Rows=3
1
2
3
Warning: mysql_fetch_arr ay(): 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_arr ay() 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.)
Aug 14 '06 #4
Rik
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_arr ay() is in the same program block.
If i try this

$result = mysql_query($qu ery)
$rows = mysql_num_rows( $result);
while ($row = mysql_fetch_arr ay($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_ass oc($arg)){
print_r($row);
}
}
$link = mysql_connect(' localhost','roo t');
mysql_select_db ('testbase',$li nk);
$result = mysql_query('SE LECT * FROM tbl_test');
check($result);
?>

Judging by your output:
>
Rows=3
1
2
3
Warning: mysql_fetch_arr ay(): 5 is not a valid MySQL result resource
in F:\webpub\php\t est.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
Aug 14 '06 #5
"Jerry Stuckle" <js*******@attg lobal.netpíše v diskusním příspěvku
news:47******** *************** *******@comcast .com...

1: <html><body>
2: <?php
3: <?php
4: $link = mysql_connect(" localhost", "user", "password")
or die("Grr: " . mysql_error());
6: mysql_select_db ("my_dbf") or die("Grr");
6: $query = "select id from my_table where id < 4 order by id";
7: $result = mysql_query($qu ery) or die("Grr: " . mysql_error());
8: $rows = mysql_num_rows( $result);
9: echo "Rows=", $rows, "<br>" ;
10: list_it($result );
11:
12: function list_it($result )
13: {
14: while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC))
15: {
16: echo $row["id"], "<br>";
17: }
18: }
19: ?>
20: </body></html>

Warning: mysql_fetch_arr ay(): 5 is not a valid MySQL result resource in
F:\webpub\php\t est.php on line 14.
The code you showed should not display this error. Unfortunately, you
left out what's probably the most important piece - the line number of the
failing code.
No error but warning, but output before warning is as I expect ;-)

--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
Aug 14 '06 #6
"Rik" <lu************ @hotmail.compíš e v diskusním příspěvku
news:c2******** *************** ****@news1.tude lft.nl...
Judging by your output:
>>
Rows=3
1
2
3
Warning: mysql_fetch_arr ay(): 5 is not a valid MySQL result resource
in F:\webpub\php\t est.php on line ...

Do the 1\n2\n3 mean these rows are shown?
Yes
It would seem a _second_ fetch is performed on the result that we're
not aware of.
Hmm, I do to study my code :-) This could be the reason.
Could you show us the entire relevant code?
No. The code is not top-secret but is too big and if I delete some parts it
could be not runable.

--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
Aug 14 '06 #7
Petr Vileta wrote:
"Jerry Stuckle" <js*******@attg lobal.netpíše v diskusním příspěvku
news:47******** *************** *******@comcast .com...

1: <html><body>
2: <?php
3: <?php
4: $link = mysql_connect(" localhost", "user", "password")
or die("Grr: " . mysql_error());
6: mysql_select_db ("my_dbf") or die("Grr");
6: $query = "select id from my_table where id < 4 order by id";
7: $result = mysql_query($qu ery) or die("Grr: " . mysql_error());
8: $rows = mysql_num_rows( $result);
9: echo "Rows=", $rows, "<br>" ;
10: list_it($result );
11:
12: function list_it($result )
13: {
14: while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC))
15: {
16: echo $row["id"], "<br>";
17: }
18: }
19: ?>
20: </body></html>

Warning: mysql_fetch_arr ay(): 5 is not a valid MySQL result resource in
F:\webpub\php\t est.php on line 14.
>The code you showed should not display this error. Unfortunately, you
left out what's probably the most important piece - the line number of
the failing code.


No error but warning, but output before warning is as I expect ;-)
OK, if this is your entire code, then the problem shouldn't occur. I've
done similar many times with ho problems.

Either you're freed the result before calling your function, or you're
calling it from someplace else. But either way you aren't passing a
valid result object.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 15 '06 #8
Hi Petr
what i want to say in my code is don't put mysql_fetch_arr ay()
funcstion in while loop condition put it inside the loop your problem
will be solved

Thanks
Ninad

Petr Vileta wrote:
"Rik" <lu************ @hotmail.compíš e v diskusním příspěvku
news:c2******** *************** ****@news1.tude lft.nl...
Judging by your output:
>
Rows=3
1
2
3
Warning: mysql_fetch_arr ay(): 5 is not a valid MySQL result resource
in F:\webpub\php\t est.php on line ...
Do the 1\n2\n3 mean these rows are shown?

Yes
It would seem a _second_ fetch is performed on the result that we're
not aware of.

Hmm, I do to study my code :-) This could be the reason.
Could you show us the entire relevant code?
No. The code is not top-secret but is too big and if I delete some parts it
could be not runable.

--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
Aug 21 '06 #9
Ninad wrote:
Petr Vileta wrote:
>>"Rik" <lu************ @hotmail.compíš e v diskusním příspěvku
news:c2****** *************** ******@news1.tu delft.nl...

>>>Judging by your output:

Rows=3
1
2
3
Warning: mysql_fetch_arr ay(): 5 is not a valid MySQL result resource
in F:\webpub\php\t est.php on line ...
Do the 1\n2\n3 mean these rows are shown?

Yes

>>>It would seem a _second_ fetch is performed on the result that we're
not aware of.

Hmm, I do to study my code :-) This could be the reason.

>>>Could you show us the entire relevant code?

No. The code is not top-secret but is too big and if I delete some parts it
could be not runable.

--

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


Hi Petr
what i want to say in my code is don't put mysql_fetch_arr ay()
funcstion in while loop condition put it inside the loop your problem
will be solved

Thanks
Ninad
(Top posting fixed)

I almost always place mysql_fetch_arr ay() in the while loop condition.
It works very well there.

P.S. Please don't top post.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 21 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2827
by: josh dismukes | last post by:
i recieve this error from this part of the code: mysql_fetch_array(): supplied argument is not a valid mysql result resource it's returning a long text from the database which is about 200 characters long. Thanks for any help that is given. <?php
3
3423
by: Pratchaya | last post by:
Hi Everyone ============================================================== About PHP::: Error/Problem PHP Warning: mysql_fetch_array(): ============================================================== In the past i use my code/script work fine with Mandrake 9.1 - 10.1 ( + apache ,mysql ) Now i move to redhat EL4 with the same...
2
18895
by: 00webman | last post by:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/html/scripts/07/view_users.php on line 15 Can anyone spot my error?!? Thanks. <?php # Script 7.6 - view_users.php (2nd version after Script 7.4) // This script retrieves all the records from the users table. $page_title = 'View the Current...
3
3905
by: petemaxi | last post by:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\tockholes\includes\menu.inc.php on line 9 <div class="left"> <div class="menu"> <div class="boxhead" style="text-align:center;"> <strong>Menu</strong> </div> <br /> <?php require ('includes/db_conn.inc.php'); $query =...
1
2083
by: myaashik | last post by:
Hello! All I have a Error message saying that: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/rocks/public_html/colorado3.php on line 32 I have error on this code below: <html> <head> <titleColorado</title>
1
2697
by: lsmamadele | last post by:
I am getting the following error messages in my search: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mamadele/public_html/BESTPLAYS/search.php on line 113 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mamadele/public_html/BESTPLAYS/search.php on...
11
3585
by: Breana | last post by:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/breana/public_html/category.php on line 88 ------------------------------------------- It does this when there is no result "empty table" how can i do a quick fix to say No Results... row 88: if ($myrow = mysql_fetch_array($result)) { do...
2
16969
by: poreko | last post by:
I am connecting to my database using Object oriented PHP. My query is returning results but at the end of my table,at the bottom of the page I keep having this error when I run my program: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\mysql_class_2.php on line 45. Can anyone help me? ...
11
4731
by: chemlight | last post by:
I'm having a problem. I'm sure I'm going to kick myself over the answer... I have a table that stores vendors and their languages. This table starts out blank. I am querying the table to see if a vendor has been added to the table yet. The problem is, if they haven't been added, I can't seem to get the script to realize that. here is what I am...
0
7750
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7989
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8182
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6369
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5271
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2170
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1271
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.