Page 1 of 1

Orderby in href not working!

Posted: Fri Feb 01, 2008 3:13 am
by ICKY
I'm new to php and had to pick up another person's development 8O 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>-->

Re: Orderby in href not working!

Posted: Fri Feb 01, 2008 4:00 am
by Kieran Huggins
please use code tags - its hard for us to read otherwise (and we often won't bother)

Code: Select all

$orderby = $_GET['orderby'];
if($orderby == NULL){
  $orderby = "horseName";
}
 
// could (should?) be
 
$orderby = isset($_GET['orderby']) ? $_GET['orderby'] : "horseName";
Also... what is my_connect() ? Is that some sort of database abstraction wrapper? It looks like it wants to be mysql_connect(). If it IS a wrapper (and database portability is important to your app), you should consider using the built-in PDO functions: http://php.net/pdo

Re: Orderby in href not working!

Posted: Fri Feb 01, 2008 12:20 pm
by ICKY
What do you mean code tags? I am new to the post and don't want people passing over my stuff because it's not easy read through.

Please look at the following and tell me if it is written correctly. Thanks.

<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>-->

Re: Orderby in href not working!

Posted: Fri Feb 01, 2008 12:58 pm
by JAM
Tags:
<?php
echo 'No tags';
?>
But after adding [code=php]tags...

Code: Select all

<?php
    echo 'No tags';
?>
Have you read the sticky posts in this forum?

Your problem:
What errors do you get? Does the scritp say something? Have you tried something else than the below? Is the red text the only thing not working in the script?

Re: Orderby in href not working!

Posted: Sat Feb 02, 2008 5:01 am
by Kieran Huggins
not to sound, well, any way in particular.... but did you read the rest of my post after "please use code tags?"