試試這個:
<?php
function curl_download($Url){
// is cURL installed yet?
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
// OK cool - then let's create a new cURL resource handle
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $Url);
// Set a referer
curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
// User agent
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
return $output;
}
$loop_counter = 1;
$hotel_query = "select hotel_id,hotel_name,trip_url,automatic_status from hotels where automatic_status='0'";
$hotel_result = mysql_query($hotel_query) or die(mysql_error());
while($hotel_row = mysql_fetch_object($hotel_result)){
$url=$hotel_row->trip_url;
echo "Loop no.".$loop_counter."<br />";
echo curl_download($url);
$loop_counter++;
}
?>
捲曲代碼爲here
嘗試使用這樣的:mysql_fetch_array($ hotel_result)) – Chris
不,它不工作太 –
你確保查詢工作...嘗試把print_r($ hotel_row);在while循環內部,這樣每次都會迴響。如果這給了你5個結果,那麼我們可以從那裏移動 – Chris