2012-06-13 59 views
0

我似乎無法得到這個工作,所有靜態數據的作品,但對下面的變量,序列化與可變轉移到另一個數據庫

$customf = $row["ps_custom_fields"]; 
     $cfarr = unserialize($customf); 
     $name = $cfarr[5]; 
     $desc = $cfarr[2]; 
     $cat = $cfarr[3]; 
     $tags = $cfarr[4]; 

我不能讓他們來進行數據來下一個數據庫,並輸入我需要的所有數據,其廣告系統運行另一個處理所有發票,購買和數據收集的數據庫,第二個數據庫只輸出到廣告網站。

//Connect to Local Server Database 
    $link1 = mysql_connect("localhost","usr","pass") or die("Opps Local Connection Failed!"); 
    $db = mysql_select_db("pulseem1_ipb",$link1) or die ("Local Connection Failed Again!"); 

//Select Result to pull 
    $result = mysql_query("SELECT ad_id, ad_image, ad_link FROM ipb_nexus_ads") 
    or die ("Results Didnt pull Correctly!"); 

//Second Results to pull 
$result2 = mysql_query("SELECT ps_custom_fields FROM ipb_nexus_purchases") 
    or die ("Second Results Didnt pull Correctly!"); 


    while ($row = mysql_fetch_array($result,$result2)) 
{ 

//Put Results into a Variable 

    $customf = $row["ps_custom_fields"]; 
    $cfarr = unserialize($customf); 
    $name = $cfarr[5]; 
    $desc = $cfarr[2]; 
    $cat = $cfarr[3]; 
    $tags = $cfarr[4]; 
    $url = $row["ad_link"]; 
    $image = $row["ad_image"]; 

} 

//Upload Advert to Remote Host with values of Variables 
//Connect To Remote Database 
    $link2 = mysql_connect("localhost","user","pass") or die("Opps Second Connection Failed!"); 
    $db = mysql_select_db("onlyclic_adverts",$link2) or die ("Second Connection Failed Again!"); 

// Insert Values from Original Database 
    mysql_query("INSERT INTO busadverts (advert_name, advert_url, advert_image, advert_description, advert_catergory, advert_tags, active) VALUES ('$name','$url','$image','$desc','$cat','$tags','1')"); 



//Release Connection and Results 

回答

0

如果我沒有弄錯,你試圖在mysql_fetch_array中傳遞兩個數據變量。該函數接受作爲資源傳遞的第一個參數,第二個參數爲結果類型,如MYSQL_ASSOC,MYSQL_NUM和MYSQL_BOTH。所以,這可能是您看到結果出現問題的原因。

沒有看到來自結果的數據,有幾個選項可以處理這些數據。您可以在循環數據之前對它們進行array_merge,或者可以分別循環遍歷每個數據集,將它們放入其受尊重的變量中。

只要你沒有看到變量的適當結果,請確保你是var_dump代碼的某些部分來查看結果。

- 答到註釋 -

陣列合併示例

while ($row = mysql_fetch_array($result1){ 
    $array1 = $row; 
} 

while ($row2 = mysql_fetch_array($result2){ 
    $array2 = $row; 
} 
//array merge 
$items = array_merge($array1, $array2); 

//Loop over data and setup variables 
foreach ($items as $id => $item){ 
    //Setup what you need while looping over items 
} 

只是遍歷數據

while ($row = mysql_fetch_array($result1){ 
    //unserialize pieces from this array and put them in the appropriate variables 
} 

while ($row2 = mysql_fetch_array($result2){ 
    //unserialize pieces from this array and put them in the appropriate variables. 
} 
+0

如果IM來的print_r($ cfarr)我可以看到從數據陣列,但不從那裏繼續,你能展示一個你已經陳述過的例子嗎? –

+0

謝謝你的工作! –

+0

不客氣! – Telshin

相關問題