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
4

1 回答 1

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. 
}
于 2012-06-13T19:41:35.017 回答