PDA

View Full Version : Text link to a recordset filter?


diesel77
05-28-2007, 12:27 PM
(PHP MYSQL)

How can I filter current results on a page from a text link
for Example put items in ascending or descending order.

davidj
05-28-2007, 03:21 PM
how clever are you with PHP

do you hand write your code

diesel77
05-28-2007, 03:59 PM
I dont program at all, But i have acheived this before from a tutorial or possibly a server behaviour. Its been a long time since ive dabbled in dymanic websites.

at the moment i just have my repeat region and i want a user to be able to click a link to sort the list into descending or ascending order etc. Like what you would see on a comparison site.

davidj
05-28-2007, 09:25 PM
ok here goes...

When i do this i always do it dynamically

like this...


switch($_GET['order']){
case '1': $order= "DESC"; break;
case '2': $order= "ASC"; break;
}


then in your SQL you can do this...

///note the $order in the sql
SELECT * FROM Table ORDER BY birth $order

then on your links you would do this...

<a href="samepage.php?order=1">sort</a>

///////////////

if you dont understand this then your going to have to do some learnin

this is quite advanced for someone who never codes

diesel77
05-29-2007, 06:01 AM
MySQL Error#: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$order' at line 1

Im using wamp 5 version 1.7.0

davidj
05-29-2007, 08:20 AM
post the SQL

diesel77
05-29-2007, 09:54 AM
SELECT * FROM table_a ORDER BY price $order

davidj
05-29-2007, 10:40 AM
post the code you have in the page

diesel77
05-29-2007, 01:57 PM
<?php
switch($_GET['order']){
case '1': $order= "DESC"; break;
case '2': $order= "ASC"; break;
}
?>

davidj
05-29-2007, 06:56 PM
post everything

all the code

diesel77
05-30-2007, 04:48 PM
<?php require_once('Connections/dabe_a.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_dabe_a, $dabe_a);
$query_Recordset1 = "SELECT * FROM table_a ORDER BY price";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $dabe_a) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

</head>

<body>
<table width="70%" border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td align="center" bgcolor="#E1E8F7">&nbsp;</td>
<td colspan="2" align="right" bgcolor="#E1E8F7"><span class="style1">Filter Price from <a href="results.php?order=2">Low to High</a> or <a href="results.php?order=1">High to Low</a></span></td>
</tr>
<?php do { ?>
<tr>
<td width="20%" align="center" class="bot-border"><p><img src="<?php echo $row_Recordset1['Prod_image']; ?>" alt="" width="90" /></p></td>
<td width="52%" class="bot-border"><p class="style3"><span class="style24"><?php echo $row_Recordset1['Prod_name_link']; ?></span><strong><br />
</strong><?php echo $row_Recordset1['description']; ?><span class="style23"><br />
<span class="style25"><?php echo $row_Recordset1['More_Info_Link']; ?></span></span><br />
</p></td>
<td width="20%" align="center" class="style26"><?php echo $row_Recordset1['price']; ?><span class="style3"><span class="style1">
<?php
switch($_GET['order']){
case '1': $order= "DESC"; break;
case '2': $order= "ASC"; break;
}
?>
</span></span></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
<tr>
<td align="center" bgcolor="#E1E8F7">&nbsp;</td>
<td colspan="2" bgcolor="#E1E8F7">&nbsp;</td>
</tr>
</table>
<p align="center" class="style3">&nbsp;</p>
<p>&nbsp;</p>
<p><a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>"></a></p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

davidj
05-30-2007, 07:21 PM
the position of where you placed the switch leads me to believe you know nothing about code. Your script has been written by dreamweaver !

im sorry but i dont offer assistance for wizard driven code. The reason being is im wasting my time because you dont learn anything. And you will be back on here when dreamweaver goes tits up coz you dont have access to the drag n drop panels.

learn to code and you will have my full attention

i appologise once again

diesel77
05-30-2007, 08:46 PM
I dont program at all, But i have acheived this before from a tutorial or possibly a server behaviour. Its been a long time since ive dabbled in dymanic websites.

I already told you that, you could have saved us both alot of time if that was your intention.

davidj
05-30-2007, 09:29 PM
i appologise again

i will post a sticky explaining my position

you would be allot better of if you were able to understand what the code did