ICKY Posted February 1, 2008 Share Posted February 1, 2008 I'm new to php and had to pick up another person's development Anyway, I have pasted what I think to be correct but it won't work. I am trying to get the hyperlink to sort the page by horse name but I will be adding other sorting options later after this problem is solved. Can someone help? //check to see if an order has been set and passed as a variable $orderby = $_GET['orderby']; if($orderby == NULL){ $orderby = "horseName"; } $order = $_GET['order']; if($order == NULL){ $order = "ASC"; } //get all the show horses //show horses have a 'horseGender' of 'c', 'f' or 'g' AND are 3 year old or over my_connect(); //work out the year that horseYOB must be greater than $minimum_year = date("Y") - 3; $query = "SELECT * FROM `horses` WHERE (`horseGender` = 'c' OR `horseGender` = 'f' OR `horseGender` = 'g') AND `horseYOB` <= '$minimum_year' AND `show_me` = '1' ORDER BY CAST(replace(horseSalePrice, '$','') as unsigned int) desc"; //printf("Query is: ".$query); $result = my_query($query); //get the number of horses which are for show $num_rows = mysql_num_rows($result); //set the 'previous_letter' variable for the first time round the loop $previous_letter_show = ""; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE></TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <link href="../br_style.css" type="text/css" rel="stylesheet" /> <link href="../print.css" type="text/css" rel="stylesheet" media="print"> </HEAD> <h4>Show Horses<div id="print"><a href="showrosterprint.php" target="_blank"><img src="images/printer1.gif" BORDER="0"><br> <span class="style1">Print</span></a></div></h4> <span class="smalltext11">Sort by:</span> <a href="tab_show.php?orderby=horseName&order=ASC"><img src="images/sort_up.gif" border="0"></a><a href="tab_show.php?orderby=horseName&order=ASC">Name</a> <a href="tab_show.php?orderby=horseName&order=DESC"><img src="images/sort_down.gif" border="0"></a> <!--</h1><a href="tab_show.php?orderby=horseYOB&order=ASC"><img src="images/sort_up.gif" border="0"></a><a href="tab_show.php?orderby=horseYOB&order=ASC">Age</a> <a href="tab_show.php?orderby=horseYOB&order=DESC"><img src="images/sort_down.gif" border="0"></a> <a href="tab_show.php?orderby=horseGender&order=ASC"><img src="images/sort_up.gif" border="0"></a><a href="tab_show.php?orderby=horseGender&order=ASC">Sex</a> <a href="tab_show.php?orderby=horseGender&order=DESC"><img src="images/sort_down.gif" border="0"></a>--> Link to comment https://forums.phpfreaks.com/topic/88858-orderby-in-href-not-working/ Share on other sites More sharing options...
Barand Posted February 1, 2008 Share Posted February 1, 2008 the query is hard-coded to sort on price <?php $query = "SELECT * FROM `horses` WHERE (`horseGender` = 'c' OR `horseGender` = 'f' OR `horseGender` = 'g') AND `horseYOB` <= '$minimum_year' AND `show_me` = '1' ORDER BY $orderby $order "; Link to comment https://forums.phpfreaks.com/topic/88858-orderby-in-href-not-working/#findComment-455118 Share on other sites More sharing options...
ICKY Posted February 1, 2008 Author Share Posted February 1, 2008 Sorry to be stupid but I how would you get around this problem? How should I do it? Ezra Link to comment https://forums.phpfreaks.com/topic/88858-orderby-in-href-not-working/#findComment-455598 Share on other sites More sharing options...
Barand Posted February 1, 2008 Share Posted February 1, 2008 You could use something like the code that I posted Link to comment https://forums.phpfreaks.com/topic/88858-orderby-in-href-not-working/#findComment-455603 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.