473,707 Members | 2,377 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 7426
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
2833
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
3433
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 code/script
2
18902
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 Users'; include ('./includes/header.html');
3
3913
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 = "select * from menu order by item_order"; $result = mysql_query($query);
1
2095
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
2706
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 line 127 My code is below. Any help would be much appreciated. ...
11
3596
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 { if ($rowcolor == 1) {
2
16976
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? The following is my PHP class: <?php class mysql {...
11
4746
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 trying to do. $testvend = SELECT language FROM vendor_details WHERE id = $vendorid ...
0
8697
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9289
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9060
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5939
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3151
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
2
2508
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2096
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.