无限的Ajax Scroll配置和php

时间:2014-01-05 08:52:12

标签: php jquery

我使用无限ajax滚动滚动到底部结果shoule显示。我找不到我犯了错误它显示mysql_num_rows()期望参数1是资源请做需要全部在此先感谢< / p>  

<div  class="content left" >
<!--  CONTENT AREA START -->

<?php

    $page = (int) (!isset($_GET['p'])) ? 1 : $_GET['p'];
# sql query
$sql = "SELECT * FROM review_news WHERE category='".$category."' ORDER BY id DESC";
# find out query stat point
$start = ($page * $limit) - $limit;
# query for page navigation
if( mysql_num_rows(mysql_query($sql)) > ($page * $limit) ){
    $next = ++$page;
}
$query = mysql_query( $sql . " LIMIT {$start}, {$limit}");
if (mysql_num_rows($query) < 1) {
    header('HTTP/1.0 404 Not Found');
    echo 'Page not found!';
    exit();
}


?>          
<script type="text/javascript" src="jquery-ias.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            // Infinite Ajax Scroll configuration
            jQuery.ias({
                container : '#loop', // main container where data goes to append
                item: '.review', // single items
                pagination: '.nav', // page navigation
                next: '.nav a', // next page selector
                loader: '<img src="ajax-loader.gif"/>', // loading gif
                triggerPageThreshold: 3 // show load more if scroll more than this
            });
        });
    </script>
            <div id="loop" class="list-view clear">

         <h3><span>Recent News</span>
               </h3>           

            <?php
             while ($row = mysql_fetch_array($query)):
            ?>              


            <div id="post_<?php echo $row['id']?>" class="review">
                <div class="post-content">
                                        <a class="post_img" href="review-default-news.php?id=<?php echo base64_encode($row['id']);?>"><img  src="<?php
                            if($row['image_name']=="")
                            {

                             echo  'http://www.kornerseat.com/news/noimage.jpg';

                                }else{
                                    ?>http://www.kornerseat.com/news/<?php echo $row['image_name'];?> <?php }?>" alt="<?php echo $row['heading'];?>" title="<?php echo $row['heading'];?>"  /> </a>

                    <div class="post_content">
                        <h2><a class="widget-title" href="review-default-news.php?id=<?php echo base64_encode($row['id']);?>"><?php echo $row['heading'];?></a></h2> 

                        <div class="post_right">
                            <!--<a href="#" class="pcomments" >4 </a>   -->

                        </div>

                        <p> 
                        <?php

if(strlen($row['news'])<=65)
  {
    echo $row['news'];
  }else{
    $y=substr($row['news'],0,150) . '...';
    echo $y;
  }
  ?>
                        <a href="review-default-news.php?id=<?php echo base64_encode($row['id']);?>" class="read_more"> Read More </a></p> 
                    </div>     
                </div>
            </div>

            <?php endwhile?>

            <!--page navigation-->
    <?php if (isset($next)): ?>
    <div class="nav">
        <a href='news.php?p=<?php echo $next?>'>Next</a>
    </div>
    <?php endif?>

                        </div>


<!--  CONTENT AREA END -->
</div>
<?php include_once('../inc/right.php')?>
<?php include_once('../inc/footer.php')?>

1 个答案:

答案 0 :(得分:0)

<div  class="content left" >
<!--  CONTENT AREA START -->

<?php

$page = (int) (!isset($_GET['p'])) ? 1 : $_GET['p'];

# find out query stat point
$start = ($page * $limit) - $limit;

# sql query
$SQL = sprintf("SELECT SQL_CALC_FOUND_ROWS * FROM review_news WHERE category='%s' ORDER BY id DESC LIMIT %d, %d", 
mysql_real_escape_string($category), (int)$start, (int)$limit);

# query for dataset
$ResDataSet  = mysql_query($SQL) or die( mysql_error() );

# query for page navigation
$ResFoundRow = mysql_query("SELECT FOUND_ROWS() AS NumRow") or die( mysql_error() );
$RowFoundRow = mysql_fetch_array($ResFoundRow);


if ( $RowFoundRow['NumRow'] <= 0) 
{
    header('HTTP/1.0 404 Not Found');
    echo 'Page not found!';
    exit();
} else if( $RowFoundRow['NumRow'] > ($page * $limit) ) {
    $next = ++$page;
}

?>          
    <script type="text/javascript" src="jquery-ias.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        // Infinite Ajax Scroll configuration
        jQuery.ias({
            container : '#loop', // main container where data goes to append
            item: '.review', // single items
            pagination: '.nav', // page navigation
            next: '.nav a', // next page selector
            loader: '<img src="ajax-loader.gif"/>', // loading gif
            triggerPageThreshold: 3 // show load more if scroll more than this
        });
    });
</script>
        <div id="loop" class="list-view clear">

     <h3><span>Recent News</span>
           </h3>           

        <?php
         while ($row = mysql_fetch_array($ResDataSet)):


        ?>