开发者

how to get values of array out

I have this array

$pv->orderRecordsArray = array();


foreach($order->records as $i=>$orderRecord){

$pv->orderRecordsArray[] = $orderRecord->orderRecordID;  
        }

// print_r($pv->orderRecordsArray) for example
// shows Array ( [0] => 46839 [1] => 46840 [2] => 46841 )

I need to use the array values from above in my sql statement below.

$sql = "
    SELECT 
    *               
         FROM 
    table1               
    WHERE 
    orderRecordID IN (46741, 46742) 
         ";

so infront of IN I wan开发者_C百科t $pv->orderRecordsArray results.

thanks


You can use implode to generate such a list:

$sql = "SELECT *
        FROM table1
        WHERE orderRecordID IN (" . implode(', ', $pv->orderRecordsArray) . ")";

But you should also consider a subquery or Join of your tables.


$sql = 'SELECT *
        FROM table1               
        WHERE orderRecordID IN ('.implode(',',$pv->orderRecordsArray).')';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜