duanchuli5647 2012-12-19 06:04
浏览 44
已采纳

strl缩短字符

I think I have it partly working, but for some reason, it's not getting the article's content..

<?php

        $amount_get = mysql_query("SELECT * FROM comment WHERE articleid='" . mysql_real_escape_string($_GET['id']) . "'"); 
        $comments = mysql_num_rows($amount_get);            

        $grab = mysql_query("SELECT * FROM articles WHERE id='" . mysql_real_escape_string($_GET['id']) . "' LIMIT 1");    
        $grab = mysql_query("SELECT id, news_title, news_content, news_author, news_day, news_month, news_year, news_date FROM articles ORDER BY id DESC limit 3"); 
        $news_day =$row['news_day'];
        $news_month =$row['news_month'];
        $news_year =$row['news_year'];

        if (mysql_num_rows($grab)==0) {
        echo "<div class='alert alert-note-x'>Sorry, it looks like their are no articles posted!</div>";
        }

        else if(strlen($row['news_contents']) > 135) {
                    $news_content = substr($news_content, 0, 135) . "....";
        }

         while($row = mysql_fetch_array($grab)){

    ?>

    <div class="post-container">
        <div class="post">
        <div class="left">
        <div class="date"><span class="day"><?php echo $row['news_day'] ?></span> <span class="month"><?php echo $row['news_month'] ?></span> <span class="year"><?php echo $row['news_year'] ?></span></div></div>
        <div class="postcontent"><h5 class="posttitle"><a href="#/media/<?php echo $row['id'] ?>.<?php echo stripslashes(str_replace(" ", "-", $row['news_title'])); ?>"><?php echo stripslashes($row['news_title']); ?></a></h5>                       

                <?php echo (strlen($row['news_content']) > 135); ?>

            </div>
    </div>​
    </div>  

  <?php } ?>

This is what it looks like: http://puu.sh/1CD32

Do you guys know why it's showing a "1" instead of what's in the database?

<?php echo (strlen($row['news_content']) > 135); ?>
  • 写回答

3条回答 默认 最新

  • dskvfdxgdo2422392 2012-12-19 06:14
    关注

    You are asking it if the variable $row['news_content'] is greater than 135 characters. It will print 1 for true and 0 for false.

    If you are trying to print the first 135 characters of the variable you are looking for substr not strlen

    echo substr($row['news_content'], 0, 135);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line