2016-03-22 19 views
1

Veritabanı: koddan $row_Recordset2['P_id'] like a 2,3 almak,Sonuç formu dizinin nasıl alınacağı?

$bid = $_GET['B_id']; 

    $sqlB ="select * from buy where B_id ='$bid' "; 
    $Recordset2 = mysql_query($sqlB, $connect) or die(mysql_error()); 
    $row_Recordset2 = mysql_fetch_assoc($Recordset2); 

Ve bu sql kodu, satın ne sonuç Gösterge:

--> product table 
    P_id P_name   P_uploadKey 
    1  Cemera   7365 
    2  Notebook  7222 
    3  Monitor   7355 
    4  Printer   7242 

    --> buy table 
    B_id P_id  B_name  date 
    1  1,3,4  somchai 12/3/2016 
    2  2,3  kri  12/3/2016 

$_GET['B_id'] = '2' satın masaya bulmak id göstermek için bu sql yukarıda:

$pid = $row_Recordset2['P_id']; 
$sqlp ="select * from buy where P_id ='$pid' "; 
$Recordset3 = mysql_query($sqlp, $connect) or die(mysql_error()); 
$row_Recordset3 = mysql_fetch_assoc($Recordset3); 
do { 
echo $row_Recordset3['P_name']. "<br>"; 
} while ($row_Recordset3 = mysql_fetch_assoc($Recordset3)); 

böyle göstermek istiyorum, bunu düzenlemek nasıl:

Notebook 
Monitor 
+0

Şimdi ne var? –

+0

Google 'JOIN',' SOL JOIN' belki de. – Epodax

+0

şimdi sadece sadece Not Defterini göster – DNu

cevap

1

Bu ben bunu yapabilirim cevaptır.

$pid = $row_Recordset2['P_id']; 

$array = explode(',', $pid); 

foreach ($array as $item) { 


$sqlp ="select * from buy where P_id ='$item' "; 
$Recordset3 = mysql_query($sqlp, $connect) or die(mysql_error()); 
$row_Recordset3 = mysql_fetch_assoc($Recordset3); 
do { 
echo $row_Recordset3['P_name']. "<br>"; 

} while ($row_Recordset3 = mysql_fetch_assoc($Recordset3));  

} 
0
Aşağıdaki gibi kullanabilirsiniz

,

$sqlp ="select * from product where P_id IN '($pid)'"; 

yerine

$sqlp ="select * from buy where P_id ='$pid' "; 
İlgili konular