Home  >  Article  >  Backend Development  >  php 列表页判断是否归藏

php 列表页判断是否归藏

WBOY
WBOYOriginal
2016-06-13 12:26:41840browse

php 列表页判断是否收藏

本帖最后由 mf0916 于 2015-10-22 18:54:06 编辑 在php文件里
<br />//$list 是个数组 包含每条信息的数据,然后写入以下代码;<br />	foreach($list as $value){<br />		$id=intval($value['id']);//list里面的信息ID<br />		$uid=intval($['uid']);//当前登录用户的ID<br />		$str = //查询数据库where likeid='$id' and uid='$uid';//有没有用户ID和当前信息ID<br />                          //查询条件就是这样,具体代码就不写了 (⊙﹏⊙)b<br />		$like = mysql_num_rows($str);	//判断出来的结果 $like大于0 表示已收藏<br />	}<br />//以上结果 输出 $like 能显示出 每条信息当前用户收藏情况是1还是0<br />//代码没有错误<br />

在html文件里
<br />{loop $list $a}<br />$a[id] - $a[title] -........<br />{/loop}<br />


问题是在html 文件里怎么判断啊?也就是说 把$like和列表的ID关联起来
//在html里面的 $list 写下如下代码 不成功
<br />{loop $list $a}<br />{if $like>0}已收藏{else}未收藏{/if}$a[id] - $a[title] -........<br />{/loop}<br />

------解决思路----------------------
看不出 $like 是从哪里来的,而且是个单值
如果是代码1中查询出来的那个,也应该放进 $list 中去吧?
对于每个 id 和 uid 对而言,$like 都是不一样的

------解决思路----------------------
$like 是在哪里赋值的?
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn