简体   繁体   English

ORDER按钮(mysqli / PHP),不同按钮相同div

[英]ORDER button (mysqli/PHP), different button same div

This is my code which display database styled content. 这是我的代码,显示数据库样式的内容。

<?php
include 'connect/con.php';

$query ="SELECT newsvid.id, newsvid.addName, newsvid.vidTitle, newsvid.url, newsvid.vidSD, newsvid.published, videoinformation.vidLD, videoinformation.vidYear, videoinformation.vidCity, videoinformation.vidZanr, videoinformation.vidZanr2, videoinformation.vidZanr3, videoinformation.vidQuality, videoinformation.vidTranslated, videoinformation.vidTime  FROM newsvid, videoinformation WHERE newsvid.id = videoinformation.id";
$order = isset($_GET['order']) ? $_GET['order'] : 'DESC';
$goodParam = array("ASC", "DESC");

if (in_array($order, $goodParam)) {
if($order == 'ASC'){
     $query .= " ORDER BY newsvid.id DESC"; 
}else{
     $query .= " ORDER BY newsvid.id ASC"; 
    }
}

$result = mysqli_query($con,$query);
echo "<div class=\"maincover \" data-role=\"scrollbox\" data-scroll=\"vertical\">";

echo "<div class=\"panel panel-default\">";
while($row = mysqli_fetch_array($result)) {
echo "<div class=\"panel-heading\">";
echo '<div><a class="panel-title btn-block vidTitle" href="details.php?id='.$row['id'].'"><h5>'.$row['id'].' | '.$row['vidTitle'].'</h5></a></div>';
echo "</div>";

echo "<div class=\"panel-body\">";
echo "<div class=\"imgCover\"><img class=\"imageCover\"src=\"" . $row['url'] . "\"></div>";
echo "<div class=\"vidSD\">" . $row['vidSD'] . "</div>";
echo "<div class=\"vidDetails\"> 


<table>
<tr><td><strong> Years: </strong></td><td>" . $row['vidYear'] . "</td></tr>
<tr><td><strong> City: </strong></td><td>". $row['vidCity'] . "</td></tr>
<tr><td><strong> Zanr: </strong></td><td>". $row['vidZanr'] ." , ". $row['vidZanr2'] ." , ". $row['vidZanr3'] . "</td></tr>
<tr><td><strong> Quality: </strong></td><td>". $row['vidQuality'] . "</td></tr>
<tr><td><strong> Translated: </strong></td><td>". $row['vidTranslated'] . "</td></tr>
<tr><td><strong> Video time: </strong></td><td>". $row['vidTime'] .  "</td></tr>
</table> 
</div></div>";

echo " <div class=\"panel-footer\">";
echo '<h6><strong>Author: </strong><a href="../userPages/user.php?u='.$row['addName'].'">'.$row['addName'].'</a></h6>';
echo '<div><h6><strong>Published: </strong>' . $row['published'] . '</h6></div>'; 
echo "</div>";
}
echo "</div></div>";

mysqli_close($con);
?>

Question is: 问题是:

I have this section: 我有此部分:

if (in_array($order, $goodParam)) {
if($order == 'ASC'){
     $query .= " ORDER BY newsvid.id DESC"; 
}else{
     $query .= " ORDER BY newsvid.id ASC"; 
    }

And I'm using buttons in my Index page: 我在“索引”页面中使用按钮:

<a href="view.php?order=ASC">ASC</a> 
<a href="view.php?order=DESC">DESC</a> 

Question is: currently I have that each button open NEW page with ordered content. 问题是:目前,我需要每个按钮打开包含有序内容的NEW页面。 I need that every time you press different ordering button, ONLY content section (div) will change and not the whole website, so that the same style will stay. 我需要每次您按下不同的订购按钮时,仅内容部分(div)会更改,而不是整个网站都将更改,以便保持相同的样式。

I confused, the way that every ordering button pressed... style of the content will be the same and only ordering will change... I know how to open content in the same page BUT I do not want to copy design every time for each content page..when theoretically I need only change the last bit of query: 我很困惑,每个订购按钮被按下的方式...内容的样式将是相同的,只有订购会改变...我知道如何在同一页面中打开内容,但是我不想每次都复制设计每个内容页面..理论上,我只需要更改查询的最后一位即可:

ORDER BY newsvid.id DESC

DESC or ASC or by DATA or NAME and etc... DESC或ASC或DATA或NAME等...

<body>
<div id="joe"></div>

<script type="text/javascript">
// Fetch and display "content.htm" inside a DIV automatically as the page loads:
ajaxpagefetcher.load("joe", "content.htm", true)
</script>

<div id="bob"></div>

<script type="text/javascript">
<!-- Fetch and display "sub/content2.htm" inside a DIV when a link is clicked on. Also load one .css file-->
<a href="javascript:ajaxpagefetcher.load('bob', 'sub/content2.htm', false, '', ['page.css'])">Load Content 2</a>
</script>

</body>

This is what I do not want to do.... or DO but change only type of ordering and not full content... 这是我不想做的。...或要做的只是更改订购类型,而不更改全部内容...

The way you have it, everytime you click the ASC or DESC button, the same page will refresh and display all the information again. 有了这种方式,每次单击ASC或DESC按钮,同一页面都会刷新并再次显示所有信息。

What you might be looking for is a web technology called Ajax. 您可能正在寻找的是一种称为Ajax的网络技术。 It's basically javascript with some api calls to refresh and load certain parts of a webpage without sending a whole server request to reload the whole html on a page again. 它基本上是javascript,带有一些api调用,可刷新和加载网页的某些部分,而无需发送整个服务器的请求以再次重新加载页面上的整个html。

Other than that, there is no way to refresh / load certains parts of a page without reloading the whole page again. 除此之外,如果不重新加载整个页面就无法刷新/加载页面的某些部分。

"Question is: currently I have that each button open NEW page with ordered content. I need that every time you press different ordering button, ONLY content section (div) will change and not the whole website, so that the same style will stay." “问题是:当前,我需要每个按钮打开带有已排序内容的NEW页面。我需要每次您按不同的排序按钮时,仅内容部分(div)会更改,而不是整个网站,以便保持相同的样式。 ”

To change just the content of the div and reload a new page, you need to use some jQuery or other javascript to update the DOM with new data on button ( actually link) click. 要仅更改div的内容并重新加载新页面,您需要使用一些jQuery或其他JavaScript来通过单击按钮(实际上是链接)的新数据来更新DOM。

If i would have faced the similar problem i had done it using "form method" of HTML since i don't know ajax currently. 如果我会遇到类似的问题,那么我已经使用HTML的“表单方法”完成了此操作,因为我目前不了解ajax。

  <?php
  if(isset($_POST['ASC']))   /* if user have clicked ASC button ,do this */
  {
     $query .= " ORDER BY newsvid.id ASC";
     echo "<div class='ur_div'>" . display() . "</div>";
  }
  if(isset($_POST['DESC']))   /* if user have clicked DESC button ,do this */
  {
     $query .= " ORDER BY newsvid.id DESC";
     echo "<div class='ur_div'>" . display() . "</div>";
  }

   echo "<form method='post' action='SamePage.php'>";
   echo "<input type='submit' name='ASC' value='ASC'>";
   echo "</form>";

   echo "<form method='post' action='SamePage.php'>";
   echo "<input type='submit' name='DESC' value='DESC'>";
   echo "</form>";
   ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM