By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,092 Members | 1,597 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,092 IT Pros & Developers. It's quick & easy.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

100+
P: 117
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:
[PHP]if ($myrow = mysql_fetch_array($result)) {

do {

if ($rowcolor == 1) {
$rowcolorhex = "#ffffff";
$rowcolor = 0;
} else {
$rowcolorhex = "#D6D6D6";
$rowcolor = 1;
}[/PHP]

It pops on most pages:
POSTED BY:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/breana/public_html/item.php on line 22
Admin
Sep 10 '07 #1
Share this Question
Share on Google+
11 Replies


100+
P: 117
I am tring to do a fix but am having trouble..
Expand|Select|Wrap|Line Numbers
  1. if ($myrow = mysql_fetch_array($result)) {
  2.   do {
  3.     if ($rowcolor == 1) {
  4.       $rowcolorhex = "#ffffff";
  5.       $rowcolor = 0;
  6.     } else {
  7.       $rowcolorhex = "#D6D6D6";
  8.       $rowcolor = 1;
  9.     }
  10. } else {
  11.   if ($myrow = ' ' {
  12.     printf (No results found);
  13.   }
  14.  
Sep 10 '07 #2

gregerly
Expert 100+
P: 192
I am tring to do a fix but am having trouble..

if ($myrow = mysql_fetch_array($result)) {

do {
if ($rowcolor == 1) {
$rowcolorhex = "#ffffff";
$rowcolor = 0;

} else {

$rowcolorhex = "#D6D6D6";
$rowcolor = 1;
}
} else {
if ($myrow = ' ' {
printf (No results found);
}
I do my row coloring a little different:

[PHP]$x=0;
//use a while loop instead of the if / do
while(list($field1,$field2,$field3,$field4)=@mysql _fetch_row($sql)){
$mod=$x%2;
$class=(!$mod)?"ws1style":"ws2style";

echo "<div class='$class'>$filed1</div>\n";

$x++;
}[/PHP]

The code above uses the modulus operator to determine which class the div should get.

Hope that helps. Also, to suppress your mysql_fetch_array() errors add an "@" in front of the call.

IE:

[PHP]@mysql_fetch_row($result);[/PHP]

Thanks,

Greg
Sep 10 '07 #3

Atli
Expert 5K+
P: 5,058
Hi.

I've changed the title of this thread to better describe it's topic.
Using good, descriptive titles that follow the Posting Guidelines will increase your chances of getting you questions answered!

Also, please but your code inside [code] tags!

Moderator
Sep 10 '07 #4

pbmods
Expert 5K+
P: 5,821
Heya, Breana.

If you're getting this error, then your MySQL query is generating an error.

You will not get an error if your query returns zero results; mysql_fetch_array() will simply return false.

Try echoing mysql_error() to see what's going on.
Sep 11 '07 #5

100+
P: 117
I dont understand what you mean by error i tried it noting showed up?

But this is new..

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/breana/public_html/results.php on line 79

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/breana/public_html/results.php on line 106

Here is how i placed the error.
echo mysql_error();

I'll put my code maybe you'll see the error..

[PHP]<?php

$pagenum = 0;

$searchtype = $_REQUEST['searchtype'];
$searchingred = $_REQUEST['searchingred'];

if ($_REQUEST['pagenum']) {$pagenum = $_REQUEST['pagenum'];}

$sql = "select * from " . SEARCH_TERMS . " where term = '$searchingred'";

$result = mysql_query($sql ,$db);

if (mysql_num_rows($result) > 0) {
echo mysql_error();

$row = mysql_fetch_row($result);
$count = $row[1];
$newcount = $count + 1;
$sql = "update " . SEARCH_TERMS . " set count = $newcount where term = '$searchingred'";

} else {

$sql = "insert into " . SEARCH_TERMS . " (term, count) values ('$searchingred', 1)";

}

$result = mysql_query($sql ,$db);

?>[/PHP]
Sep 11 '07 #6

code green
Expert 100+
P: 1,726
You would help yourself a lot by using simple error trapping and echoing out the values of variables.
At the moment you are blundering about blindly.
This warning
Expand|Select|Wrap|Line Numbers
  1. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
means that $result is empty. This is because the following query has failed
[PHP]$sql = "select * from " . SEARCH_TERMS . " where term = '$searchingred'";
$result = mysql_query($sql ,$db);
[/PHP]You cannot use mysql_functions on a non existent resultset.
If you echo out $result you expect to see something like '#1'
If you echo out $sql you will probably see why the query is wrong.
Sep 11 '07 #7

100+
P: 117
I don't understand what you mean?
Like this: echo mysql_error($sql);

Or other?
Sep 11 '07 #8

code green
Expert 100+
P: 1,726
[PHP]echo 'searchtype'.$searchtype;
echo 'searchingred'.$searchingred;
echo 'sql'.$sql;
//Execute the query
echo 'error'.mysql_errno();
echo 'errno'.mysql_error();

echo 'result'.$result;

//Execute the loop[/PHP]And let the dog see the rabbit!
Sep 11 '07 #9

100+
P: 117
Ok, lol here is what it said:

searchtypeIsearchingredsqlinsert into SEARCH_TERMS (term, count) values (''free cars, 1)error1146errnoTable 'breana_cheatz911.SEARCH_TERMS' doesn't existresult

I just looked the table is there!
[PHP]
--
-- Table structure for table `search_terms`
--

CREATE TABLE `search_terms` (
`term` varchar(255) default NULL,
`count` int(10) unsigned default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `search_terms`
--

INSERT INTO `search_terms` VALUES ('zombie', 11);
INSERT INTO `search_terms` VALUES ('Code/Game', 1);
INSERT INTO `search_terms` VALUES ('1701', 1);
INSERT INTO `search_terms` VALUES ('harvest moon', 1);
INSERT INTO `search_terms` VALUES ('alarm clock', 1);
INSERT INTO `search_terms` VALUES ('delete', 1);
INSERT INTO `search_terms` VALUES ('gta', 1);
INSERT INTO `search_terms` VALUES ('harvest', 3);[/PHP]
Sep 11 '07 #10

100+
P: 117
NM, i got it fixed, i looked at the error and said oops..

I had it selecting the table like this :SEARCH_TERMS
In stead of like this: search_terms

Now the error has vanished and it updates the search keys :)

Now if i can just figure out how to display the top 10 search words i am all good...
Sep 11 '07 #11

pbmods
Expert 5K+
P: 5,821
Heya, Breana.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)

I presume you are referring to this thread.
Sep 11 '07 #12

Post your reply

Sign in to post your reply or Sign up for a free account.