$sayList[] = array(
'hctitle'=>$row['title'],
'hcurl'=>$row['url'],
'wailian'=>"<a href='".$row['wailian']."' target=blank>".$row['title']."</a>",
'link'=>"<a href='".$row['url']."'>".$row['title']."</a>",
'tupian'=>"<a href='".$row['url']."'><img src='".$row['thumb']." '/></a>",
'riqi'=>date('Y-m-d',$row['createtime'])
);
}
这是ajax调用的数据,想问一下怎么判断一个字段为空的话,显示另一个字段,如果在普通PHP里面,知道用if($row['wailian']==''){echo $row['url'];},但是在这里面不会写了,请教一下。
'link'=>if "(".$row['wailian'].")=="''{echo "<a href='".$row['url']."'>"}else{"<a href='".$row['wailian']."'>"}.$row['title']."</a>",我是这样写的,肯定不对吧?新手求大神写法啊
6 个解决方案
#1
<div class="single_item newslist">
<dl class="clearfix">
<dt>
<div class="wailian"></div>
<br>
<span class="riqi"></span>
</dt>
<dd><div class="tupian"></div></dd>
</dl>
</div>
<a href="javascript:;" class="get_more">加载更多</a>
这是前台调用的,我想加个外链字段,如果有值就显示外链的地址,如果为空就显示原来文章的url
<dl class="clearfix">
<dt>
<div class="wailian"></div>
<br>
<span class="riqi"></span>
</dt>
<dd><div class="tupian"></div></dd>
</dl>
</div>
<a href="javascript:;" class="get_more">加载更多</a>
这是前台调用的,我想加个外链字段,如果有值就显示外链的地址,如果为空就显示原来文章的url
#2
请先复习一下基本的语法知识
#3
哪有好的教程啊 ,能告诉怎么写吗
#4
PHP手册,我都是查那个
#5
我是这样实现的,$query=mysql_query("select * from sssh_article where catid=5 and posid<>1 order by id desc limit $last,$amount");
while ($row=mysql_fetch_array($query)) {
if($row['wailian']==''){
$sayList[] = array(
'hctitle'=>$row['title'],
'hcurl'=>$row['url'],
'link'=>"<a href='".$row['url']."'>".$row['title']."</a>",
'tupian'=>"<a href='".$row['url']."'><img src='".$row['thumb']." '/></a>",
'riqi'=>date('Y-m-d',$row['createtime'])
);}
else
{
$sayList[] = array(
'hctitle'=>$row['title'],
'hcurl'=>$row['url'],
'link'=>"<a href='".$row['wailian']."' target=_blank>".$row['title']."</a>",
'tupian'=>"<a href='".$row['url']."'><img src='".$row['thumb']." '/></a>",
'riqi'=>date('Y-m-d',$row['createtime'])
);}
}
echo json_encode($sayList);
不知道代码是否严谨
while ($row=mysql_fetch_array($query)) {
if($row['wailian']==''){
$sayList[] = array(
'hctitle'=>$row['title'],
'hcurl'=>$row['url'],
'link'=>"<a href='".$row['url']."'>".$row['title']."</a>",
'tupian'=>"<a href='".$row['url']."'><img src='".$row['thumb']." '/></a>",
'riqi'=>date('Y-m-d',$row['createtime'])
);}
else
{
$sayList[] = array(
'hctitle'=>$row['title'],
'hcurl'=>$row['url'],
'link'=>"<a href='".$row['wailian']."' target=_blank>".$row['title']."</a>",
'tupian'=>"<a href='".$row['url']."'><img src='".$row['thumb']." '/></a>",
'riqi'=>date('Y-m-d',$row['createtime'])
);}
}
echo json_encode($sayList);
不知道代码是否严谨
#6
先转换下瞅一眼,你这看着累
$query=mysql_query("select * from sssh_article where catid=5 and posid<>1 order by id desc limit $last,$amount");
while ($row=mysql_fetch_array($query)) {
if($row['wailian']==''){
$sayList[] = array(
'hctitle'=>$row['title'],
'hcurl'=>$row['url'],
'link'=>"<a href='".$row['url']."'>".$row['title']."</a>",
'tupian'=>"<a href='".$row['url']."'><img src='".$row['thumb']." '/></a>",
'riqi'=>date('Y-m-d',$row['createtime'])
);}
else
{
$sayList[] = array(
'hctitle'=>$row['title'],
'hcurl'=>$row['url'],
'link'=>"<a href='".$row['wailian']."' target=_blank>".$row['title']."</a>",
'tupian'=>"<a href='".$row['url']."'><img src='".$row['thumb']." '/></a>",
'riqi'=>date('Y-m-d',$row['createtime'])
);}
}
echo json_encode($sayList);
#1
<div class="single_item newslist">
<dl class="clearfix">
<dt>
<div class="wailian"></div>
<br>
<span class="riqi"></span>
</dt>
<dd><div class="tupian"></div></dd>
</dl>
</div>
<a href="javascript:;" class="get_more">加载更多</a>
这是前台调用的,我想加个外链字段,如果有值就显示外链的地址,如果为空就显示原来文章的url
<dl class="clearfix">
<dt>
<div class="wailian"></div>
<br>
<span class="riqi"></span>
</dt>
<dd><div class="tupian"></div></dd>
</dl>
</div>
<a href="javascript:;" class="get_more">加载更多</a>
这是前台调用的,我想加个外链字段,如果有值就显示外链的地址,如果为空就显示原来文章的url
#2
请先复习一下基本的语法知识
#3
哪有好的教程啊 ,能告诉怎么写吗
#4
PHP手册,我都是查那个
#5
我是这样实现的,$query=mysql_query("select * from sssh_article where catid=5 and posid<>1 order by id desc limit $last,$amount");
while ($row=mysql_fetch_array($query)) {
if($row['wailian']==''){
$sayList[] = array(
'hctitle'=>$row['title'],
'hcurl'=>$row['url'],
'link'=>"<a href='".$row['url']."'>".$row['title']."</a>",
'tupian'=>"<a href='".$row['url']."'><img src='".$row['thumb']." '/></a>",
'riqi'=>date('Y-m-d',$row['createtime'])
);}
else
{
$sayList[] = array(
'hctitle'=>$row['title'],
'hcurl'=>$row['url'],
'link'=>"<a href='".$row['wailian']."' target=_blank>".$row['title']."</a>",
'tupian'=>"<a href='".$row['url']."'><img src='".$row['thumb']." '/></a>",
'riqi'=>date('Y-m-d',$row['createtime'])
);}
}
echo json_encode($sayList);
不知道代码是否严谨
while ($row=mysql_fetch_array($query)) {
if($row['wailian']==''){
$sayList[] = array(
'hctitle'=>$row['title'],
'hcurl'=>$row['url'],
'link'=>"<a href='".$row['url']."'>".$row['title']."</a>",
'tupian'=>"<a href='".$row['url']."'><img src='".$row['thumb']." '/></a>",
'riqi'=>date('Y-m-d',$row['createtime'])
);}
else
{
$sayList[] = array(
'hctitle'=>$row['title'],
'hcurl'=>$row['url'],
'link'=>"<a href='".$row['wailian']."' target=_blank>".$row['title']."</a>",
'tupian'=>"<a href='".$row['url']."'><img src='".$row['thumb']." '/></a>",
'riqi'=>date('Y-m-d',$row['createtime'])
);}
}
echo json_encode($sayList);
不知道代码是否严谨
#6
先转换下瞅一眼,你这看着累
$query=mysql_query("select * from sssh_article where catid=5 and posid<>1 order by id desc limit $last,$amount");
while ($row=mysql_fetch_array($query)) {
if($row['wailian']==''){
$sayList[] = array(
'hctitle'=>$row['title'],
'hcurl'=>$row['url'],
'link'=>"<a href='".$row['url']."'>".$row['title']."</a>",
'tupian'=>"<a href='".$row['url']."'><img src='".$row['thumb']." '/></a>",
'riqi'=>date('Y-m-d',$row['createtime'])
);}
else
{
$sayList[] = array(
'hctitle'=>$row['title'],
'hcurl'=>$row['url'],
'link'=>"<a href='".$row['wailian']."' target=_blank>".$row['title']."</a>",
'tupian'=>"<a href='".$row['url']."'><img src='".$row['thumb']." '/></a>",
'riqi'=>date('Y-m-d',$row['createtime'])
);}
}
echo json_encode($sayList);