加载更多mysql结果而不更新整个页面

bmp9r5qi  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(248)

我正在加载一个查询,其中我最想在一个div中显示3个结果。下面的代码正适合于此。当我想进入下一页并再加载3个时,它同样工作正常。
唯一的问题是,整页都在更新,每次我来回。有人能帮我解决这个问题吗,所以当我返回一个前进时,只有div更新了新的结果,整个页面没有更新,只是保持原样。谢谢您

<div class="row">
    <div class="col-md-6">
    <div class="infobox-large">

    <?
    $con = connectDB();
    $query = "SELECT `id` FROM `users` WHERE `email`='$email'";
    $result = mysql_query($query, $con) or die($query."<br/> 
    <br/>".mysql_error());
    $user_id = mysql_result($result, 0);

    // Sætter maks antal pr side
    $offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0; // Hvis ikke 
    $offset er sat, sættes den til 0
    $pr_side = 3; // Antal resultater pr. side

    // Tæller antal poster i databasen
    $tael = mysql_query("SELECT COUNT(*) AS antal from tb_user_tip where 
    user_id = '".$user_id."' and point=''") or die (mysql_error());
    $antal = mysql_result($tael,0);

    $limit = 3;
    $pages = ceil($antal/$limit);

    if(isset($_GET['offset']) && is_numeric($_GET['offset'])){
        if($_GET['offset'] < 1){
            $offset = 1;
        }elseif($_GET['offset'] > $pages){
            $offset = $pages;
        }else{
            $offset = intval($_GET['offset']);
        }
    }else{
        $offset = 1;
    }

    $end  = $offset * $limit;
    $start = $end - $limit;
    ?>             

<span class="headline-box grey">Nuværende tips <?echo "(".$antal.")";?> 
</span><br /><br />          

<?
$sql_current = "select * from tb_user_tip where user_id = '".$user_id."' and 
point='' order by start_date_time ASC LIMIT $start,$pr_side";
$result = mysql_query($sql_current, $con);
$current_tip_array = array();
while($row_current = mysql_fetch_array($result)){
    $home = $row_current['home_name'];
    $away = $row_current['away_name'];

    $home_image_name = "";
    if (strpos(strtolower($home), " ") != false) {
        $arrName = split(" ", strtolower($home));
        for ($i = 0; $i < sizeof($arrName) - 1; $i++) {
            $home_image_name = $home_image_name . $arrName[$i] . "-";
        }
        $home_image_name = $home_image_name . $arrName[sizeof($arrName) - 1] 
. ".png";
        //$home_image_name = $arrName[0]."-".$arrName[1].".png";
    } else {
        $home_image_name = strtolower($home) . ".png";
    }
    $away_image_name = "";
    if (strpos(strtolower($away), " ") != false) {
        $arrName = split(" ", strtolower($away));
        for ($i = 0; $i < sizeof($arrName) - 1; $i++) {
            $away_image_name = $away_image_name . $arrName[$i] . "-";
        }
        $away_image_name = $away_image_name . $arrName[sizeof($arrName) - 1] 
. ".png";
        //$home_image_name = $arrName[0]."-".$arrName[1].".png";
    } else {
        $away_image_name = strtolower($away) . ".png";
    }

    $home_image = "/images/soccer/" . $home_image_name;
    $away_image = "/images/soccer/" . $away_image_name;
    $item_current = array(
        "event_id" => $row_current['event_id'],
        "home_name" => $row_current['home_name'],
        "away_name" => $row_current['away_name'],
        "start_date_time" => $row_current['start_date_time'],
        "league_name" => $row_current['league_name'],
        "market_style" => $row_current['market_style'],
        "odd_style" => $row_current['odd_style'],
        "odd" => $row_current['odd'],
        "tip_amount" => $row_current['tip_amount'],
        "home_image" => $home_image,
        "away_image" => $away_image
    );
    array_push($current_tip_array, $item_current);

    echo "<div class='tip-box neautral bg-white grey heading-in-box'>";
    //Tip left - home name, league
    echo "<div class='home text-left'><span class='large green 
bold'>".$row_current['home_name']."</span><br /><br />Liga<br /><span 
class='darkgreen tiny bold'>".$row_current['league_name']."</span></div>";

    //Tip center - date & time, logo home & away, market style, odds style    
    echo "<div class='logoodds'><span class='darkgreen tiny bold'>".$row_current['start_date_time']."</span><br /><br /><img src='../".$home_image."' class='HOME team_img'> - <img src='../".$away_image."' class='AWAY team_img'><br /><br /><span class='darkgreen small bold'>".$row_current['market_style']."<br />".$row_current['odd_style']."&nbsp;".$row_current['odd']."</span></div>";

    //Tip right - away name, tip amount
    echo "<div class='away text-right'><span class='large green bold'>".$row_current['away_name']."</span><br /><br />Indsats<br /><span class='darkgreen tiny bold'>".$row_current['tip_amount']."</span></div>";     
    echo "</div>";  

    }

    if($offset > 1)
    echo '<a href="?offset='.($offset-1).'"><img src="img/arrowbackgreen50.png" class="arrow_small"></a>';
    echo '' . $offset . ' af ' . $pages . '&nbsp;';
    if($offset < $pages)
    echo '<a href="?offset='.($offset+1).'"><img src="img/arrowgreen50.png" class="arrow_small"></a>';

    ?>

    </div>
  </div>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题