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. 

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

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

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.