所以我想做的是:运行这个查询:SELECT FW_ArtSrcLink FROM FW_ArtSrc WHERE OneSet =1
它输出两个结果:
我想将这两个结果附加到$result
var 并通过结果(为 2 - 如图所示)作为$r
,然后输出的部分$r
因此为
# Source of Article Info-->
$SrcTitle=$newsStory[$i]->title;
$SrcLink=$newsStory[$i]->link;
# Actual News Article Info -->
$title=$newsStory[$i]->title;
$desc=$newsStory[$i]->description;
完整代码如下所示,目前仅从sports.yahoo.com/tennis/rss.xml的第二个结果中提取:
## Loop through results from mysql
try{
#connection string
// $dbconn = new PDO('mysql:host=localhost;port=3306;dbname=mydatabase',array(PDO::ATTR_PERSISTENT => true));
$dbconn = new PDO('mysql:host=localhost;port=3306;dbname=mydatabase','myuser','mypass',array(PDO::ATTR_PERSISTENT => true));
$q = $dbconn->prepare("SELECT FW_ArtSrcLink FROM FW_ArtSrc WHERE OneSet=1");
#call stored proc
$q->execute();
#get the rows into an array
$result = $q->fetchAll();
$newsStory[] = array();
foreach($result as $r){
$xmlUrl = $r['FW_ArtSrcLink'];
$ConvertToXml = simplexml_load_file($xmlUrl);
# -> Setup XML
$newsStory = $ConvertToXml->channel->item;
}
# -----> Load News Stories
for($i = 0;$i<sizeof($newsStory); $i++){
# Source of Article Info-->
$SrcTitle=$newsStory[$i]->title;
$SrcLink=$newsStory[$i]->link;
# Actual News Article Info -->
$title=$newsStory[$i]->title;
$desc=$newsStory[$i]->description;
# Output Results ------------>
echo '<hr>';
echo '<strong>'.'Title:'.$title.'</strong>'.'(via: <a href=\''.$SrcLink.'\'>'.$SrcTitle.'</a>'.'<br />';
//echo 'Link:'.$link.'<br />';
echo 'Description'.$desc.'<br>';
##echo 'count '.count($result);
echo '<hr>';
}
} // try
我在这里做错了什么?
来自单个 db 结果的简单输出示例,我将其称为硬编码结果而不是动态使用
$xmlUrl ="http://edge1.catalog.video.msn.com/videoByTag.aspx?tag=Fox%20Sports_NBA%20news&ns=MSNVideo_Top_Cat&mk=us&sd=-1&sf=ActiveStartDate&vs=0&ind=&ps=&rct=&ff=88&responseEncoding=rss&title=FOX%20Sports%20Video%20on%20MSN:%20NBA&template=foxsports&p=foxsports";
$ConvertToXml = simplexml_load_file($xmlUrl);
: