473,396 Members | 2,013 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,396 software developers and data experts.

Using Forms in PHP-select option (Drop down list)

Hi,
I'm using the following code to show the category = thoughts. I have three categories, when i select thoughts only it has to show the thoughts category. If i select other category it has to show that particular category details. I don't know how i have to mention the particular category. Please help me.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_POST['submit']) && ($_POST['submit']=="GO"))
  3. {
  4. $sqlquery2="select * from news where category like '%thoughts%'";
  5.  
  6. $queryresult2 = mysql_query($sqlquery2) or die(mysql_error());
  7.  
  8. while ($arr2=mysql_fetch_array($queryresult2))
  9. {
  10.       echo $arr2["day"]."<br>";
  11.  
  12.       echo $arr2["category"]."<br>";
  13.  
  14.       echo $arr2["title"]."<br>";
  15.  
  16.       echo $arr2["article"]."<br>";
  17. }
  18. }
  19. ?>
  20.  
  21.  
  22. <form action="test2.php" method="post">
  23. <hr>
  24. <h4>"Category"</h4>
  25. Select your Category:
  26. <select name="category">
  27.   <option value="thoughts">thoughts</option>
  28.   <option value="travel">Travel</option>
  29.   <option value="important_events" selected="selected">Important_Events</option>
  30. </select>
  31. <input type="submit" name="submit" value="GO" />
  32.  
  33. </form>
  34.  
  35. </body>
  36. </html>
  37.  
May 15 '08 #1
2 2938
Atli
5,058 Expert 4TB
Hi.

Would it not work to simply put the option you selected into the query?
Expand|Select|Wrap|Line Numbers
  1. $category = $_POST['category'];
  2. $sqlquery2="select * from news where category like '%{$category}%'";
  3.  
Also...
Please use [code] tags when posting your code examples. (See How to ask a question)

[code=php] ...PHP code goes here... [/code]

Thanks.
May 15 '08 #2
TheServant
1,168 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. $sqlquery2="select * from news where category like '%thoughts%'";
  2. $queryresult2 = mysql_query($sqlquery2) or die(mysql_error());
Also, do you need all (*) of your information? You could replace the above by:
[PHP]$queryresult = mysql_query (

SELECT day, category, title, article
FROM news
WHERE category = '$category'
)
or die(mysql_error());[/PHP]
This is probably more efficient I believe. Also, you can use some MySQL coding like I have done. I have capitals for SQL commands and then space it out appropriately for ease of reading.
May 15 '08 #3

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

Similar topics

3
by: Jim Johnstone | last post by:
Some details of my HOME PC. I am running the following .... Win2000 SP4; IE V6; 512MB RAM; H/Disk Space OK. In the past couple of weeks I have installed/configured from binaries for .. MySQL...
2
by: yoelgold | last post by:
Hi I want to start writing a new site. It will include 3 forms that will collect information from the user. I know how to keep the info in sessions etc. my question is about the design of the...
11
by: WindAndWaves | last post by:
Hi Gurus What I would like to do is to setup a little form where people can put in a date (e.g. Day: Month..... Year , where ... is user input) and subsequently, will take them through to an...
2
by: Sam White | last post by:
I have set up a MySQL db on one server, IIS 6.0 on another. Using Frontpage I created some forms to input data. On a test page I made, I have 4 fields. First is the ID which is autonumber (I leave...
9
by: Marc | last post by:
Okay, here's the problem - I have 3 radio buttons, and 11 check boxes (which are disabled by default). I have the javascript below which when the last radio button is clicked, enables the...
6
by: Rulla | last post by:
Hi , It is my ifrst time trying to use any script langauge , I have to learn it by today and tomorrow because I am doing my dissreattion and I need it to my project so I will appreciate any help as...
4
by: Bouzy | last post by:
Hello I am having a problem with forms. I know they are easy for some people, but I am new. I am trying to make a simple feedback form. Hear is what I have so far... <?php //process the email...
4
by: dirk | last post by:
Hey, I'm new to php and I'm trying to write some php code so that I can insert data into a mysql database using html forms. I've got two text forms and a submit button. When entering data and...
5
by: Reds | last post by:
HI, I have just started using Web Forms. It seems that I'm not able to do some things that Windows Forms allow me to do. For example, I tried to implement a counter using a module level...
2
by: Will Bumgardner | last post by:
Hello all! I'm using Dreamweaver 8 to build forms for a website I am building/maintaining. I can build the form just fine, but now I need a fairly simple PHP code to be able to have the forms...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.