Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2010
    Posts
    23
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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

  • #2
    New Coder
    Join Date
    Jul 2010
    Posts
    23
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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" ;


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •