473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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,category 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.......


Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE  HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd"> 
  2.     <html> 
  3.       <head> 
  4.         <meta  http-equiv="Content-Type" content="text/html;  charset=iso-8859-1"> 
  5.         <title>Search  Contacts</title>
  6.  
  7.       </head> 
  8.       <p><body> 
  9.         <h3>Search  Topic Details</h3> 
  10.  
  11.         <form  method="post" action="search_next_topic.php?go"  id="searchform"> 
  12.           TopicHead: <input  type="text" name="topic_head" id="topic_head" /> 
  13.           Deptname: <select name="dept_name" id="dept_name">
  14.        <?php
  15.  
  16.       include("connect_db.php");
  17.  
  18.             $select_dept=mysql_query("select department_id,department_name from department");
  19.  
  20.                         while($name_dept=mysql_fetch_array($select_dept))
  21.                         {
  22.                         $dept_id=$name_dept[department_id];
  23.  
  24.                          echo "<option value='$dept_id'> $name_dept[department_name]</option>";    
  25.                          }
  26.                              ?>
  27.  
  28.  
  29.     </select> CategoryName: <select name="category_name" id="category_name">&nbsp; 
  30.     <?php
  31.       include("connect_db.php");
  32.  
  33.             $select_cat=mysql_query("select * from category");
  34.  
  35.                         while($name_cat=mysql_fetch_array($select_cat))
  36.                         {
  37.                         $category_id1=$name_cat[id];
  38.  
  39.                            echo "<option value='$category_id1'> $name_cat[category_name]</option>";
  40.                          }            
  41.  
  42.  
  43.  
  44.                         ?></select> SubCategoryName:<select name="subcategory_name" id="subcategory_name">
  45.     <?php
  46.       include("connect_db.php");
  47.  
  48.         $select_subcat=mysql_query("select * from subcategory");
  49.                  while($name_subcat=mysql_fetch_array($select_subcat))
  50.                         {
  51.                         $subcategory_id1=$name_subcat[id];
  52.  
  53.                            echo "<option value='$subcategory_id1'> $name_subcat[subcategory_name]</option>";    
  54.                            }
  55.                                ?> </select>
  56.           <input  type="submit" name="submit" value="Search"> 
  57.  
  58.           <div id="list_div" align="center">
  59.           <p>&nbsp;</p>
  60. <table width="500" height="50" border="1" align="center">
  61. <tr>
  62. <th width="50">Category</th>
  63. <th width="50">Subcategory Name</th>
  64. <th width="50">Heading</th>
  65. <th width="50">Content</th>
  66. <th width="121">Department Name</th>
  67. <th width="95">Next Topic</th>
  68. <th width="57">Related Topics</th>
  69. </tr>
  70.  
  71.  
  72. <?php
  73.      extract($_REQUEST);
  74.   if(isset($_POST['submit'])){
  75.   if(isset($_GET['go'])){
  76.  
  77.    include("connect_db.php");
  78.  
  79.   //-query  the database tabl
  80.  
  81.  
  82.  $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");
  83.   //-run  the query against the mysql query function  
  84.  
  85.  $num=mysql_num_rows($sql);
  86.  
  87.   //-create  for loop and loop through result set
  88.   for($i=1;$i<=$num;$i++)
  89.         {
  90.         $name =mysql_fetch_array($sql);
  91.         $var_id=$name['id'];
  92.         $next_top_id=$name['next_topic'];
  93.  
  94.  
  95.  $next_topic1=mysql_query("select topic_head from topics where id='$next_top_id' and deleted=0");
  96. $next_topic2=mysql_fetch_array($next_topic1);
  97.  
  98.  
  99. $related_topic_sql=mysql_query("select t.topic_head from topics t,related_topics r where 
  100. r.topic_id='$var_id' and t.id=r.related_id and t.deleted=0 and r.deleted=0");
  101. $related_topic2=mysql_fetch_array($related_topic_sql);
  102.  ?>
  103.  
  104.                                <tr>
  105.                                <td><?php echo $name['category_name']; ?></td>
  106.                                <td><?php echo $name['subcategory_name']; ?></td>
  107.                                <td><?php echo $name['topic_head'];?></td>
  108.                                <td><?php echo $name['content'];?></td>
  109.                                <td><?php echo $name['department_name'];?></td>
  110.                                <td><?php echo $next_topic2['topic_head']; ?></td>
  111.                                 <td><?php echo  $related_topic2['topic_head'];?></td>
  112.                                 </tr>
  113.  
  114.             <?php
  115.  
  116.  
  117.   }
  118.  
  119.   }
  120.  
  121.  
  122.   }
  123.  
  124.  
  125. ?>
  126. </table>
  127. </div>
  128. </form>
  129.  
  130.  
  131.  
  132.       </body> 
  133.     </html>
Sep 16 '10 #1
2 1972
Wrong forum.
Use MySQL
Sep 19 '10 #2
Markus
6,050 Expert 4TB
Rizladonovich, in future, just hit the 'report' button and the mods will take care of it :)
Sep 19 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: googleboy | last post by:
I didn't think this would be as difficult as it now seems to me. I am reading in a csv file that documents a bunch of different info on about 200 books, such as title, author, publisher, isbn,...
3
by: JIM.H. | last post by:
Hello, I am suing SELECT * from MyTable in a stored procedure and populate dropdown list. By using followings: ddlSP.DataSource = DS; ddlSP.DataTextField = "PName"; ddlSP.DataValueField = "PID";...
2
by: Achim Domma (Procoders) | last post by:
Hi, to allow my user to select from a list of values which are calculated on the fly, I tried to generate a list of LinkButton controls on the fly. But the connected event does not fire. ...
5
by: JP SIngh | last post by:
Hi All This is a complicated one, not for the faint hearted :) :) :) Please help if you can how to achieve this search. We have a freetext search entry box to allow users to search the...
2
by: mikeingenito | last post by:
Hello, I have a a web form where i dynamically load a user control. The web page is an issue log, and each user control I add is a specific issue. I load them as follows: Try ...
4
by: PI | last post by:
Hi guys, I'm struggling with this much longer than I think I need to, I guess you could help me here: How do I make the results of a search display on the same page as the search, sort of beneath...
3
by: IP This | last post by:
Good Day Good People... I have a table with various fields, a number of fields relate to the same data type, i.e. Language1, Language2, Language3, Language4, - I want to be able to search all of...
11
by: mrking | last post by:
Hi, First time in the Java section here. I have an HTML form and a PHP script to do a simple calculation but it has to take me to a different page for the results. The calculator is really...
482
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. ...
14
by: kip1790 | last post by:
See example here Ultimately I want the image created to display next to the update button in the same browser window instead of loading into a new window. Then every time I input text and click...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.