Jump to content

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


Help!php

Recommended Posts

I am getting an error message.

mysql_fetch_array(): supplied argument is not a valid MySQL result
My Sql seems to work fine. But I kept on getting this error message whenever I try to view orderid. I have option to view different field such as orderid, orderdate, price and profit. When the page loads its fine. But when I try to view orderdate the orderid I get the error message

 

Error code is on the first line and the other places where it says $result.

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td align='left'>" . $row['orderid'] . "</td>";
  echo "<td align='left' style='font-size:12px;'>" . $row['orderdate'] . "</td>";
  echo "<td align='left' style='font-size:12px;'>" . $row['updated'] . "</td>";  
  echo "<td align='left' style='font-size:12px;'>" . $row['name'] . "</td>";
   echo "<td align='left' style='font-size:12px;'>" . $row['price'] . "</td>";
  echo "<td align='left'>" . $row['salesman'] . "</td>";
  echo "<td align='left'>" . $row['origsalesman'] . "</td>";
  echo "<td align='left'>" . $row['status'] . "</td>";
  echo "<td align='left'>" . $row['product'] . "</td>";
  echo "<td align='left'>£" . $row['profit'] . "</td>";  
  echo "</tr>";

  echo "<tr><td colspan='10'><hr></td></tr>";
  }
  
  if ( mysql_num_rows( $result ) == 0 )
echo "<tr><td colspan='10'>No orders found<hr></td></tr>";
echo "</table></form>";




mysql_free_result( $result );code]

Please help me. 

Link to comment
Share on other sites

Its a query that I get from the database.

 

 if ( $_GET[ 'indexes' ] == "All,All,Order id") {
     $sql_query = "SELECT * FROM printersales p
LEFT JOIN orderdetail o ON ( p.orderid = o.orderid )
LEFT JOIN printers pr ON ( o.productid = pr.productid )
WHERE p.updated > '" . $dateStartMonth . " 00:00:01' ORDER BY orderid DESC"; 
  $result = mysql_query($sql_query);
} else {
  $sql_query = "SELECT * FROM printersales p
LEFT JOIN orderdetail o ON ( p.orderid = o.orderid )
LEFT JOIN printers pr ON ( o.productid = pr.productid )
WHERE p.updated > '" . $dateStartMonth . " 00:00:01' {$criteria}";
  $result = mysql_query($sql_query);

 

This query works fine on the database. And it does show result on the page but when I changed to view different field and come back to orderid. it shows that error message

Link to comment
Share on other sites

change this line:

 

$result = mysql_query($sql_query);

 

to this:

 

$result = mysql_query($sql_query) or die(mysql_error());

 

this will tell you whats going wrong with your sql, $result should be a resource that mysql_fetch_array() can work on, but it isn't so this should spit out the sql error that you are getting

 

Link to comment
Share on other sites

I found out that there is something wrong with the query. It created duplicate data and not sure how to get rid of that. my query is

 

SELECT DISTINCT o.orderid, p.orderdate, p.updated, pr.name, pr.rrp, p.origsalesman, p.salesman,p.statu FROM printersales p
LEFT JOIN orderdetail o ON ( p.orderid = o.orderid )
LEFT JOIN printers pr ON ( o.productid = pr.productid )
WHERE p.updated > '2012-02-2 00:00:01' ORDER BY o.orderid DESC

 

When I join tables thats where the problem starts and it duplicate orderid.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.