我似乎无法使其工作,所有静态数据都有效,但对于下面的变量,
$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 :(得分: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.
}