加载更多的mysql结果,而无需更新整个页面

时间:2018-10-16 11:56:14

标签: php html css mysql

我正在加载一个查询,我最大希望在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>

0 个答案:

没有答案