php - Using Link change content ORDERING BY DESC, ASC and e.t.c. of the SAME page -
this view page:
<?php include 'connect/con.php'; $result = mysqli_query($con,"select newsvid.id, newsvid.vidtitle, newsvid.url, newsvid.vidsd, newsvid.published, videoinformation.vidld, videoinformation.vidyear, videoinformation.vidcity, videoinformation.vidzanr, videoinformation.vidquality, videoinformation.vidtranslated, videoinformation.vidtime newsvid, videoinformation newsvid.id = videoinformation.id order newsvid.id desc"); while($row = mysqli_fetch_array($result)) { echo '<div class="id">#<a href="details.php?id='.$row['id'].'">'.$row['id'].'</a></div>'; echo "<div class=\"vidtitle\">" . $row['vidtitle'] . "</div>"; echo "<div class=\"imgcover\"><img class=\"imagecover\"src=\"" . $row['url'] . "\"></div>"; echo "<div class=\"vidsd\">" . $row['vidsd'] . "</div>"; echo "<div class=\"viddetails\"> <table class=\"tablesd\" > <tr><td class=\"tdbr\"><strong> years: </strong></td><td class=\"tdb\">" . $row['vidyear'] . "</td></tr> <tr><td class=\"tdbr\"><strong> city: </strong></td><td class=\"tdb\">". $row['vidcity'] . "</td></tr> <tr><td class=\"tdbr\"><strong> zanr: </strong></td><td class=\"tdb\">". $row['vidzanr'] . "</td></tr> <tr><td class=\"tdbr\"><strong> quality: </strong></td><td class=\"tdb\">". $row['vidquality'] . "</td></tr> <tr><td class=\"tdbr\"><strong> translated: </strong></td><td class=\"tdb\">". $row['vidtranslated'] . "</td></tr> <tr><td class=\"tdbr\"><strong> video time: </strong></td><td class=\"tdb\">". $row['vidtime'] . "</td></tr> </table> </div>"; echo "<div class=\"published\"><strong>published: </strong>" . $row['published'] . "</div>"; } mysqli_close($con); ?>
i need link in index.php page bit "order newsvid.id desc
" changes according clicked link.
eg:
<div class="mainleftcover"> <a href="#>asc</a> | <a href="#>desc</a> | </div>
if press asc view.php page show result ordered newsvid.id asc , if press desc same view.php page show result ordered newsvid.id desc , on...
first require add together parameter link url
<div class="mainleftcover"> <a href="view.php?order=asc">asc</a> <a href="view.php?order=desc">desc</a> </div>
then set variable stub of query minus order part.
$query ="select newsvid.id, newsvid.vidtitle, newsvid.url, newsvid.vidsd, newsvid.published, videoinformation.vidld, videoinformation.vidyear, videoinformation.vidcity, videoinformation.vidzanr, videoinformation.vidquality, videoinformation.vidtranslated, videoinformation.vidtime newsvid, videoinformation newsvid.id = videoinformation.id";
use isset() ternary operator either parameter or if not set pass default.
$order = isset($_get['order']) ? $_get['order'] : 'desc';//change asc if want default
use in_array()to sanitise
$goodparam = array("asc", "desc"); if (in_array($order, $goodparam)) {
then utilize .=
concatenation assignment build $query.
if($order == 'desc'){ $query .= " order newsvid.id desc"; }else{ $query .= " order newsvid.id asc"; } } $result = mysqli_query($con,$query);
php mysql database hyperlink sql-order-by
No comments:
Post a Comment