Hi Can anyone help me i have database with data and now i like an option when uses looks at categories to sort data by hits and date if he clicks on link hits data automaticly orders by hits or date then data automaticly orders by data.. can someone help me here is the page category http://www.netbaza.net/index.php?cat_id=24 sample code this code orders by hits but i want a second option when it ordes by date also $sql = mysql_query("SELECT * FROM netbaza_movies WHERE catergory_id=".$cat_id." AND published=1 ORDER BY hits DESC LIMIT $from, $max_results" Thanks
$sql = mysql_query("SELECT * FROM netbaza_movies WHERE catergory_id=".$cat_id." AND published=1 ORDER BY hits,date DESC LIMIT $from, $max_results" And just add a , after date and add other rows u wanna order by after that
i didn#T mean like that i want to have like two links on my category page and when you click link 1 data sorts by date and when you click link 2 data sorty by hits thanks
Hi , I have seen your website you want sort system on them right "Date Aded | Top Rated | Most Watched" Thanks,
add links like <a href="index.php?cat_id=<?php echo intval($_GET['cat_id']);?>&sort=1">Hits</a> | <a href="index.php?cat_id=<?php echo intval($_GET['cat_id']);?>&sort=2">Date</a> | <a href="index.php?cat_id=<?php echo intval($_GET['cat_id']);?>&sort=3">Title</a> PHP: you then need to run an if statement or switch to get the sort order $sort = intval($_GET['sort']); if(!empty($_GET['sort']) && $sort == 3) { $orderby = " ORDER BY title ASC "; } elseif(!empty($_GET['sort']) && $sort == 2) { $orderby = " ORDER BY date DESC "; } else { //this is our default $orderby = " ORDER BY hits DESC "; } $sql = mysql_query("SELECT * FROM netbaza_movies WHERE catergory_id=".$cat_id." AND published=1 ".$orderby." LIMIT $from, $max_results"); PHP: