Q:

MySQL error on query

i'm getting the following error:
mysql_num_rows(): supplied argument is not a valid MySQL result resource in
this is the query:
$select ="SELECT * FROM tbl_order $keyValue WHERE archive ='' ORDER BY $OrderByValue";
$sel=mysql_query($select);
$Rows = 0;
$Rows = mysql_num_rows($sel);
if($Rows > 0){
    while($row=mysql_fetch_object($sel)){

        $id1 = $row->id;
        $date1 = $row->date;
        $initial1 = $row->initial;
        $description1 = $row->description;
        $pricequoted = $row->pricequoted;
        $customer1 = $row->customer;
        $phone1 = $row->phone;
        $company1 = $row->company;
        $orderedby1 = $row->orderedby;
        $orderdate1 = $row->orderdate;    
        $ordered1 = $row->ordered;    
        $contacted1 = $row->contacted;    
        $collected1 = $row->collected; 
        $freightco1 = $row->freightco;  
        $outcome1 = $row->outcome;
        $receipt1 = $row->receipt;
        $archive1 = $row->archive;
?>

can someone give me a hand with this?
cheers,
dan

I took this from his comment, I think it is relevant.
<?php 
$OrderByValue = ''; 

if($_REQUEST['orderbycolumn'] != '') { 
    $OrderByValue = $_REQUEST['orderbycolumn']." ".$_REQUEST['order']; 
} elseif($_REQUEST['orderbyvalue'] != '') { 
    $OrderByValue = $_REQUEST['orderbyvalue']; 
} else { 
    $OrderByValue = 'id'; 
} 

$KeyW = ''; 
$keyValue = ''; 

if($_REQUEST['keyword'] != '') { 
    $KeyW = $_REQUEST['keyword']; 
    $keyValue = "where $OrderByValue like '%$KeyW%'"; 
} 

?>

A:

A main problem is that you have two where clauses.
if($_REQUEST['keyword'] != '') { 
    $KeyW = $_REQUEST['keyword']; 
    $keyValue = "where $OrderByValue like '%$KeyW%'"; 
} 

$select ="SELECT * FROM tbl_order $keyValue WHERE archive ='' ORDER BY $OrderByValue";

This would mean that the following would happen
SELECT * FROM tbl_order WHERE $OrderByValue like '%$KeyW%' WHERE archive ='' ORDER BY $OrderByValue

This is invalid SQL syntax, you may need one where clause.

