Ajax与jQuery& amp; PHP XML API

时间:2015-03-13 03:18:13

标签: php jquery ajax

我正在尝试创建一个Ajax分页系统来显示我的XML API(SOAP)结果。

我有一个简单的例子,告诉我如何从mysql数据库中获取结果。但是我需要从XML API&获取我的结果。数据库中。

示例: jQuery的:

$(document).ready(function() {
    $("#results" ).load( "fetch_pages.php"); //load initial records

    //executes code below when user click on pagination links
    $("#results").on( "click", ".pagination a", function (e){
        e.preventDefault();
        $(".loading-div").show(); //show loading element
        var page = $(this).attr("data-page"); //get page number from link
        $("#results").load("fetch_pages.php",{"page":page}, function(){ //get content from PHP page
            $(".loading-div").hide(); //once done, hide loading element
        });

    });
});

PHP

//get total number of records from database for pagination
    $results = $mysqli_conn->query("SELECT COUNT(*) FROM paginate");
    $get_total_rows = $results->fetch_row(); //hold total records in variable
    //break records into pages
    $total_pages = ceil($get_total_rows[0]/$item_per_page);

    //get starting position to fetch the records
    $page_position = (($page_number-1) * $item_per_page);

    //SQL query that will fetch group of records depending on starting position and item per page. See SQL LIMIT clause
    $results = $mysqli_conn->query("SELECT id, name, message FROM paginate ORDER BY id ASC LIMIT $page_position, $item_per_page");

    //Display records fetched from database.

    echo '<ul class="contents">';
    while($row = $results->fetch_assoc()) {
        echo '<li>';
        echo  $row["id"]. '. <strong>' .$row["name"].'</strong> &mdash; '.$row["message"];
        echo '</li>';
    }  
    echo '</ul>';


    echo '<div align="center">';
    /* We call the pagination function here to generate Pagination link for us. 
    As you can see I have passed several parameters to the function. */
    echo paginate_function($item_per_page, $page_number, $get_total_rows[0], $total_pages);
    echo '</div>';
}

HTML:

<div class="loading-div"><img src="ajax-loader.gif" ></div>
<div id="results"><!-- content will be loaded here --></div>

我有:

  • XML API中的变量:$boardType[n]$hotelPrices[n]$availHotels[n]->rooms[n]->roomCategory;

  • 来自MYSQL的变量:$hotelName[n]$hotelAddress[n]$img[n][x]等。

到目前为止构建的代码是:

//get total number of records from database for pagination
    $results = count($availHotels);
    $get_total_rows = $results->fetch_row(); //hold total records in variable
    //break records into pages
    $total_pages = ceil($get_total_rows[0]/$item_per_page);

    //get starting position to fetch the records
    $page_position = (($page_number-1) * $item_per_page);

    //SQL query that will fetch group of records depending on starting position and item per page. See SQL LIMIT clause
    $results = mysql_query("SELECT , HotelAddress, HotelImages, Destination, StarRating  FROM HotelList where HotelCode= '$hotelc' ORDER BY id ASC LIMIT $page_position, $item_per_page" , $link);
    //Display records fetched from database.

    echo '<ul class="contents">';
    while($row = $results->fetch_assoc()) {
        echo '<li>';
        echo  $row["HotelName"]. '. <strong>' .$row["HotelAddress"].'</strong> &mdash; '.$row["Destination"];
        echo '</li>';
    }  
    echo '</ul>';


    echo '<div align="center">';
    /* We call the pagination function here to generate Pagination link for us. 
    As you can see I have passed several parameters to the function. */
    echo paginate_function($item_per_page, $page_number, $get_total_rows[0], $total_pages);
    echo '</div>';
}

页面返回空

0 个答案:

没有答案