How to select any one of multiple fields from search and display in list in same page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vinayamujumdar
    New Member
    • Sep 2010
    • 1

    #1

    How to select any one of multiple fields from search and display in list in same page

    Hi


    I have 1 textbox and 3 drop down menus. textbox is to pick a topic_head and the other dropdown lists are to
    select dept_name,categ ory name and sub actegory name from different tables into single topics table.

    The user selects any of these fields then hits submit
    he should list all entries in the table. How would I formulate the
    select statment for MySQL to display the results in a webpage.


    Here is the code for this.......


    Code:
    <!DOCTYPE  HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd"> 
    	<html> 
    	  <head> 
    	    <meta  http-equiv="Content-Type" content="text/html;  charset=iso-8859-1"> 
    	    <title>Search  Contacts</title>
           
    	  </head> 
    	  <p><body> 
    	    <h3>Search  Topic Details</h3> 
    	  
    	    <form  method="post" action="search_next_topic.php?go"  id="searchform"> 
    	      TopicHead: <input  type="text" name="topic_head" id="topic_head" /> 
              Deptname: <select name="dept_name" id="dept_name">
           <?php
    	   
    	  include("connect_db.php");
    	    	
    			$select_dept=mysql_query("select department_id,department_name from department");
    			
    						while($name_dept=mysql_fetch_array($select_dept))
    						{
    						$dept_id=$name_dept[department_id];
    						
    						 echo "<option value='$dept_id'> $name_dept[department_name]</option>";	
    						 }
    						 	?>
    						 
         
        </select> CategoryName: <select name="category_name" id="category_name">&nbsp; 
    	<?php
    	  include("connect_db.php");
    	    	
    			$select_cat=mysql_query("select * from category");
    			
    						while($name_cat=mysql_fetch_array($select_cat))
    						{
    						$category_id1=$name_cat[id];
    					
    						   echo "<option value='$category_id1'> $name_cat[category_name]</option>";
    						 }			
    						  
    							
    					
            				?></select> SubCategoryName:<select name="subcategory_name" id="subcategory_name">
    	<?php
    	  include("connect_db.php");
    	    	
    		$select_subcat=mysql_query("select * from subcategory");
    		         while($name_subcat=mysql_fetch_array($select_subcat))
    						{
    						$subcategory_id1=$name_subcat[id];
    				
    						   echo "<option value='$subcategory_id1'> $name_subcat[subcategory_name]</option>";	
    						   }
    						   	?> </select>
    	      <input  type="submit" name="submit" value="Search"> 
         
              <div id="list_div" align="center">
              <p>&nbsp;</p>
    <table width="500" height="50" border="1" align="center">
    <tr>
    <th width="50">Category</th>
    <th width="50">Subcategory Name</th>
    <th width="50">Heading</th>
    <th width="50">Content</th>
    <th width="121">Department Name</th>
    <th width="95">Next Topic</th>
    <th width="57">Related Topics</th>
    </tr>
         
          
    <?php
    	 extract($_REQUEST);
      if(isset($_POST['submit'])){
      if(isset($_GET['go'])){
      
       include("connect_db.php");
      
      //-query  the database tabl
     
     
     $sql=mysql_query("select t.id,t.topic_head,t.content,t.publish,t.next_topic,c.category_name,s.subcategory_name,d.department_name from topics t,category c,subcategory s,department d where t.topic_head LIKE '$topic_head%' and t.department_id = $dept_name  and  t.category_id=$category_name and t.subcategory_id=$subcategory_name and   d.department_id=t.department_id and  c.id=t.category_id and s.id=t.subcategory_id and t.deleted=0 and s.deleted=0 and c.deleted=0 and d.deleted=0");
      //-run  the query against the mysql query function  
      
     $num=mysql_num_rows($sql);
      
      //-create  for loop and loop through result set
      for($i=1;$i<=$num;$i++)
    		{
    		$name =mysql_fetch_array($sql);
    		$var_id=$name['id'];
    		$next_top_id=$name['next_topic'];
    			
    			
     $next_topic1=mysql_query("select topic_head from topics where id='$next_top_id' and deleted=0");
    $next_topic2=mysql_fetch_array($next_topic1);
     
    
    $related_topic_sql=mysql_query("select t.topic_head from topics t,related_topics r where 
    r.topic_id='$var_id' and t.id=r.related_id and t.deleted=0 and r.deleted=0");
    $related_topic2=mysql_fetch_array($related_topic_sql);
     ?>
      
                                   <tr>
                                   <td><?php echo $name['category_name']; ?></td>
    			                   <td><?php echo $name['subcategory_name']; ?></td>
    			                   <td><?php echo $name['topic_head'];?></td>
    							   <td><?php echo $name['content'];?></td>
    							   <td><?php echo $name['department_name'];?></td>
    							   <td><?php echo $next_topic2['topic_head']; ?></td>
    							    <td><?php echo  $related_topic2['topic_head'];?></td>
    							    </tr>
    			                
                <?php
    			
      
      }
      
      }
     
      
      }
      
      
    ?>
    </table>
    </div>
    </form>
    
    
    
    	  </body> 
    	</html>
    Last edited by Markus; Sep 16 '10, 10:53 AM. Reason: Please use [code][/code] tags
  • Rizladonovich
    New Member
    • Sep 2010
    • 13

    #2
    Wrong forum.
    Use MySQL

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Rizladonovich, in future, just hit the 'report' button and the mods will take care of it :)

      Comment

      Working...