SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dropdown Menu sorted by name

    Can someone help me? I don't know how to get this dropdown list to sort by products_options_values_name

    Here is the code below:

    Code PHP:
    <?php 
     
    //return the setting options
     
    // consists of: Shape 5, Type 1, Size 6, Material 7
    //if a value has been selected, it will show as selected.
     
    $opts = array( 1 => 'Decibel', 2 => 'Need');
     
    // the number before the word represents the option ID in the `product_options` table
    // the word after contains the displayed name of the dropdown box, which would usually be the same as the name
     
    //title of the box
     
    $heading = 'Quick Search';
     
    // you should not need to edit below this line 
    //------------------------
     
    $mainhtml = ""; //the var to hold all of the html
     
    foreach ( $opts as $opt => $name) {
     
    	unset($html);
     
    	$html = "<tr><td width='161px'>
    				$name 
    			</td></tr>
    			<tr><td>
    			<SELECT name='$opt' onchange='document.m_srch.submit();'>
    			<OPTION value='not'>---</OPTION>";//print the name of the box and start the drop down
     
    	$sql = "SELECT `products_options_values_id` from `products_options_values_to_products_options` WHERE `products_options_id`='$opt'"; 
    	$res = tep_db_query($sql);// get the values of all the options for that catagory
    	while($id = tep_db_fetch_array($res)){
     
    		$optnamear = tep_db_query("SELECT `products_options_values_name` from `products_options_values` WHERE `products_options_values_id`='$id[products_options_values_id]'");
     
    		$optname = tep_db_fetch_array($optnamear);
     
    		//create the dropdown
     
    		$html .= "<OPTION value='$id[products_options_values_id]' ";
     
    		if($_GET[$opt] == $id['products_options_values_id']){
    			$html .= "selected='selected'"; // if the product has already been selected keep it selected!
    			} 
     
    		$html .= ">$optname[products_options_values_name]</OPTION>";
     
     
    		}
     
    		$mainhtml .= $html."</SELECT></td></tr>";
     
     
     
    	} 
     
     
    echo "<tr><td>
    <table border='0' width='100%' cellspacing='0' cellpadding='0'>
      <tr>
        <td height='14' class='infoBoxHeading'><img src='images/infobox/corner_left.gif' border='0' alt='' width='11' height='14'></td>
        <td  width='100%' height='14' class='infoBoxHeading' align='center'>$heading &nbsp;</td>
    	</tr>
    	</table>
    	<table border='0' width='100%' cellspacing='0' cellpadding='1' class='infoBox'>
    			<tr><td>
    			<table class='infoBoxContents'>
    			<FORM name='m_srch' action='advanced_search_result.php' method='get'>
    			<INPUT type='hidden' value='1' name='m_op'> <INPUT type='hidden' value='1' name='keywords'> \n
    			$mainhtml
    			</table>
    			</td></tr>
    			</FORM>
    		</table>
    	</td></tr>";  
     
    ?>
    Last edited by TechnoBear; Sep 22, 2012 at 12:14. Reason: PHP code tags added


Bookmarks

Posting Permissions

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