我有一个问题......如何在php中将变量从函数传递给另一个函数.. 我的第一个功能:
public function get($obj_id)
{
$exclude = array();
$query = $this->db->query("SELECT
a.id as id_article ,
a.title,
a.content,
a.date,
a.views,
a.smallimage,
a.largeimage,
tin.id,
t.id,
group_concat(t.name) as tags,
group_concat(t.id) as id_tag
from tags_in_news tin
inner join articles a on a.id = tin.news_id
inner join tags t on t.id = tin.tag_id
and a.id = $obj_id
group by a.id");
if ($query->num_rows()>0)
{
foreach ($query->result() as $cr)
{
array_push($exclude,$cr->id_article);
$newsIds = implode(',',array_values($exclude));
}
}
else
{
$newsIds = 0;
}
echo "<pre>"; print_r($newsIds); echo "</pre>";
return $query->row_array();
}
和第二个功能:
public function getLastArticles()
{
$this->load->database();
$last_articles = $this->db->query("SELECT
* FROM articles WHERE id NOT IN (".($newsIds).")
ORDER BY date desc LIMIT 3");
if ($last_articles->num_rows())
{
$last_articles = $last_articles->result_array();
}
else
{
$last_articles = NULL;
}
return $last_articles;
}
当我写print_r($ newsIds)时,我得到了正确的id,但是我想在第二种方法中使用错误是未定义的变量:newsIds帮助我了...... Thx