I have this error appearing

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /websites/123reg/LinuxPackage21/th/er/ag/theragereport.co.uk/public_html/feed/feed_view.php on line 148

from this code

$sql3="SELECT view FROM $tbl_name2 WHERE id='40'";
$result3=mysql_query($sql3);

$rows=mysql_fetch_array($sql3);
$view=$rows['view'];

// if have no counter value set counter = 1
if(empty($view)){
$view=1;
$sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='40'";
$result4=mysql_query($sql4);
}

// count more value
$addview=$view+1;
$sql5="update $tbl_name set view='$addview' WHERE id='40'";
$result5=mysql_query($sql5);

any help would be hot

Regards Ryan Cosans

Hi,

Try to isolate what is the mysql_fetch_array output..So, you may want to try running a test query instead. Something like this

if (!($rows = mysql_fetch_array($sql3)))
    {
        return null;
      ## or maybe to print or echo something if there is none, but the return null has to be commented above.
       echo "There is nothing to show";
    }
## if the statement above is false, then we can echo
$view=$rows['view'];
echo $view;

Another helpful hint is to add or die(mysql_error()); on your query..

$rows=mysql_fetch_array($sql3)or die(mysql_error());

Overall, I prefer to use the first one above, because how about if id = 40 does not even exist due to auto increment?

Your problem is here

$rows=mysql_fetch_array($sql3);

This should be

$rows=mysql_fetch_array($result3);
commented: yes +7

simplypixie is correct. You need to pass resultset as the argument not query. And also check whether the view is keyword of Mysql. We can't use keyword as column name. otherwise change your query as

$sql3="SELECT `view` FROM $tbl_name2 WHERE id='40'";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.