Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-08-2012, 02:23 PM   PM User | #1
Mark-Jones
New Coder

 
Join Date: Jul 2010
Posts: 23
Thanks: 3
Thanked 0 Times in 0 Posts
Mark-Jones is an unknown quantity at this point
Form Only Works Once!

Hi

The form only works the once after page load. I fixed this a long time ago but can't for the life of me remember how I did it.

Code:
		<form method="POST" name="sorting" action="<?=seo_links('browse', $cats, catid2name($cats), 1, _SEO)?>">
			Sort:<select name="sortby" class="inputtext">
				<option value="Add_Date">Date</option>
				<option value="ProductName">Product Name</option>
				<option value="USDPrice">Price</option>
				<option value="hits">Downloads</option>
			</select>
			<select name="order" class="inputtext">
				<option value="ASC">Ascending</option>
				<option value="DESC">Descending</option>
			</select>
			<input class="inputbutton" type="submit" name="Go" value="Go" />
		</form>

<?
/// END 
// OUTPUT DATA 
			$sql = "select * from ura_items WHERE CategoryID = \"$cats\" ORDER BY Add_Date DESC LIMIT $set_limit, $limit" ; 
			
			if( isset($_POST['sortby']) && isset($_POST['order']) ) {
				$sort = magicSlashes($_POST['sortby']);
				$order = magicSlashes($_POST['order']);
				//( empty($sort) ) ? $sort = "Add_Date" : "";
				//( empty($order) ) ? $order = "DESC" : "";
				$sql = "select * from ura_items WHERE CategoryID = \"$cats\" ORDER BY '".$sort."' ".$order." LIMIT $set_limit, $limit" ; 
				}
			
			$result = mysql_query($sql) ; 
			$j = 0; 
			while ($row = mysql_fetch_array($result)) 
			{ 
			($j % 2) ? $div = "list2" : $div = "list";
			echo "<div class=\"".$div."\">";

$str .= $row['LongDesc'];
$str=str_replace('<BR>', ' ', $str);
$str=str_replace('<P>', ' ', $str);

			echo "<a href=\"".seo_links('detail', $row['ProductID'], $row['ProductName'], 1, _SEO)."\">".$row['ProductName']."</a> ".is_special($row['Add_Date'], $row['hits'], $row['status'])." <br><span class=\"listdesc\">".fewchars($str, 200)."</span> <br>";
			echo '</div>';
			$j++;
			} 

// END OUTPUT DATA
Regards
Mark-Jones is offline   Reply With Quote
Old 06-08-2012, 04:49 PM   PM User | #2
Mark-Jones
New Coder

 
Join Date: Jul 2010
Posts: 23
Thanks: 3
Thanked 0 Times in 0 Posts
Mark-Jones is an unknown quantity at this point
Fixed it!

All I had to do was remove the quotes on this part of the code:
Code:
$sql = "select * from ura_items WHERE CategoryID = \"$cats\" ORDER BY '".$sort."' ".$order." LIMIT $set_limit, $limit" ;
It now reads like this:

Code:
$sql = "select * from ura_items WHERE CategoryID = \"$cats\" ORDER BY $sort $order LIMIT $set_limit, $limit" ;
Mark-Jones is offline   Reply With Quote
Reply

Bookmarks

Tags
forms

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:28 PM.


Advertisement
Log in to turn off these ads.