why am I getting this error from this code?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • behindspace

    why am I getting this error from this code?

    this is the error that I'm getting:

    Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result
    resource in /**/**/**/content/bin/tests/price/searchHist.php on line 48

    and here is my code: (I removed commented out lines for space saving)

    echo "<table width='500' border='0' align='center' cellpadding='0'
    cellspacing='0' >
    <tr>
    <td width='200'>Par t No.</td>
    <td width='20'>Pric e</td>
    <td width='20'>Curr ency</td>
    <td width='40'>Mont h</td>
    <td width='40'>Year </td>
    </tr> \n";
    $connect = mysql_connect ("******", "******", "*****") or
    die ("Error connecting to database");
    $selected = mysql_select_db ("fishpricinghi st", $connect) or
    die ("Error connecting to database");

    $part = $_GET["partno"];

    $query = "SELECT * FROM pricehistory WHERE partno LIKE %".$part."%
    ORDER BY year DESC";

    $result = mysql_query($qu ery, $connect);

    $rows = mysql_num_rows( $result); //this is line 48 (my error line)

    for ($I = 0 ; $I < $rows ; $I++)
    {
    $partno = mysql_result($r esult, $I, "partno");
    $price = mysql_result($r esult, $I, "price");
    $currency = mysql_result($r esult, $I, "currency") ;
    $month = mysql_result($r esult, $I, "month");
    $year = mysql_result($r esult, $I, "year");

    echo "<tr><td>".$par tno."</td>
    <td>".$price. "</td>
    <td>".$currency ."</td>
    <td>".$month. "</td>
    <td>".$year." </td></tr>\n";
    }

    echo "</tr>
    </table>";

  • Gordon Burditt

    #2
    Re: why am I getting this error from this code?

    >this is the error that I'm getting:[color=blue]
    >
    >Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result
    >resource in /**/**/**/content/bin/tests/price/searchHist.php on line 48
    >
    >and here is my code: (I removed commented out lines for space saving)[/color]

    You have a syntax error in your query. print mysql_error($co nnect)
    is your friend.
    [color=blue]
    > $query = "SELECT * FROM pricehistory WHERE partno LIKE %".$part."%
    >ORDER BY year DESC";[/color]

    $query might end up as:

    SELECT * FROM pricehistory WHERE partno LIKE %widget% ORDER BY year DESC

    See some quotes missing around %widget% ?

    Gordon L. Burditt

    Comment

    • behindspace

      #3
      Re: why am I getting this error from this code?

      thanks, I figured this out already though.. it needed to be:

      $query = "SELECT * FROM pricehistory WHERE partno LIKE \"%".$part." %\"
      ORDER BY year DESC"

      Now the question, would be how to sort by "year" DESC and subsort by
      "month" DESC, so january would be last and december would be first

      any suggestions? thanks for the help on the original, it hadn't posted by
      the time I had figured it out so I couldn't clarify that I had figured it
      out before it posted

      Comment

      • Gordon Burditt

        #4
        Re: why am I getting this error from this code?

        >thanks, I figured this out already though.. it needed to be:[color=blue]
        >
        >$query = "SELECT * FROM pricehistory WHERE partno LIKE \"%".$part." %\"
        >ORDER BY year DESC"
        >
        >Now the question, would be how to sort by "year" DESC and subsort by
        >"month" DESC, so january would be last and december would be first[/color]

        Doesn't:
        ORDER BY year DESC, month DESC
        work?

        Gordon L. Burditt

        Comment

        • behindspace

          #5
          Re: why am I getting this error from this code?

          didn't try it, I'm kind of an idiot today... it's a Monday :(

          thanks for the help again :)

          Comment

          Working...