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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Breana
    New Member
    • Aug 2007
    • 117

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

    Warning: mysql_fetch_arr ay(): 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_arr ay($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_arr ay(): supplied argument is not a valid MySQL result resource in /home/breana/public_html/item.php on line 22
    Admin
  • Breana
    New Member
    • Aug 2007
    • 117

    #2
    I am tring to do a fix but am having trouble..
    [code=php]
    if ($myrow = mysql_fetch_arr ay($result)) {
    do {
    if ($rowcolor == 1) {
    $rowcolorhex = "#ffffff";
    $rowcolor = 0;
    } else {
    $rowcolorhex = "#D6D6D6";
    $rowcolor = 1;
    }
    } else {
    if ($myrow = ' ' {
    printf (No results found);
    }
    [/code]
    Last edited by Atli; Sep 10 '07, 09:57 PM. Reason: Added [code] tags and cleaned up the code a bit.

    Comment

    • gregerly
      Recognized Expert New Member
      • Sep 2006
      • 192

      #3
      Originally posted by Breana
      I am tring to do a fix but am having trouble..

      if ($myrow = mysql_fetch_arr ay($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($fie ld1,$field2,$fi eld3,$field4)=@ mysql_fetch_row ($sql)){
      $mod=$x%2;
      $class=(!$mod)? "ws1style":"ws2 style";

      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_arr ay() errors add an "@" in front of the call.

      IE:

      [PHP]@mysql_fetch_ro w($result);[/PHP]

      Thanks,

      Greg

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        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

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          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_arr ay() will simply return false.

          Try echoing mysql_error() to see what's going on.

          Comment

          • Breana
            New Member
            • Aug 2007
            • 117

            #6
            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_arr ay(): 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($sq l ,$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($sq l ,$db);

            ?>[/PHP]

            Comment

            • code green
              Recognized Expert Top Contributor
              • Mar 2007
              • 1726

              #7
              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
              Code:
              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($sq l ,$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.

              Comment

              • Breana
                New Member
                • Aug 2007
                • 117

                #8
                I don't understand what you mean?
                Like this: echo mysql_error($sq l);

                Or other?

                Comment

                • code green
                  Recognized Expert Top Contributor
                  • Mar 2007
                  • 1726

                  #9
                  [PHP]echo 'searchtype'.$s earchtype;
                  echo 'searchingred'. $searchingred;
                  echo 'sql'.$sql;
                  //Execute the query
                  echo 'error'.mysql_e rrno();
                  echo 'errno'.mysql_e rror();

                  echo 'result'.$resul t;

                  //Execute the loop[/PHP]And let the dog see the rabbit!

                  Comment

                  • Breana
                    New Member
                    • Aug 2007
                    • 117

                    #10
                    Ok, lol here is what it said:

                    searchtypeIsear chingredsqlinse rt into SEARCH_TERMS (term, count) values (''free cars, 1)error1146errn oTable 'breana_cheatz9 11.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]

                    Comment

                    • Breana
                      New Member
                      • Aug 2007
                      • 117

                      #11
                      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...

                      Comment

                      • pbmods
                        Recognized Expert Expert
                        • Apr 2007
                        • 5821

                        #12
                        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.

                        Comment

                        Working...