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

Search with a dropdown menu by value

hello,

I've got this
Expand|Select|Wrap|Line Numbers
  1. <td><select name="req" id="req">
  2.         <option value="1">posted trips</option>
  3.         <option value="2">requested trips</option>
  4.     </select></td>
  5.  
Expand|Select|Wrap|Line Numbers
  1. if($type == 'like' && $status='1' && $req='1')
  2.       {
  3.         $sql = 'SELECT * FROM topic WHERE (dstate LIKE '."'%$search%') AND status='1' AND req='1'";
  4.       }
  5.  
what i want is, when posted trips option is selected to query just the posts that contain 1 in the "req" in the database.

it looks like my script has an error somewhere
Sep 17 '10 #1

✓ answered by patrioticcow

i found the answer

Expand|Select|Wrap|Line Numbers
  1. $req = intval ($_GET['req']);
  2. if($type == 'like' && $status='1' && $req > 0 && $req < 3)
  3. {
  4. $sql = "SELECT * FROM topic WHERE (Title LIKE '%$search1%') AND req= $req"";
  5. }
  6.  

8 1536
johny10151981
1,059 1GB
Expand|Select|Wrap|Line Numbers
  1. if($type == 'like' && $status='1' && $req='1')
  2.  
this whole line is buggy....

$status='1'

this will set value '1' to $status.

$req='1'

this will set value '1' to $req. none of them are condition.
Sep 17 '10 #2
thanks for reply.

i can get rid of $status='1'

but how do i set up the condition for the $req considering the 2 values?
Sep 17 '10 #3
johny10151981
1,059 1GB
I think you are missing some point.
When you press submit button
it hit an action page which is defined in form tag.

if your method is GET then you can receive your data by
$_GET['req']; // you will get the value

if the method is POST then you can receive your data by
$_POST['req'];

in both case req is defined in the page from where you select the value.
Sep 17 '10 #4
Markus
6,050 Expert 4TB
As was hinted at before, you're assigning data to a variable (=) instead of comparing it(==).
Sep 17 '10 #5
i might be missing the point :) but i still don't understand.
can u point me toward an example?
Sep 17 '10 #6
johny10151981
1,059 1GB
try this small example and fix syntax by yourself

sub.htm
Expand|Select|Wrap|Line Numbers
  1.  <form action="test.php" method=get>
  2.   <select name="req_get" id="req">
  3.          <option value="1">posted trips</option>
  4.          <option value="2">requested trips</option>
  5.   </select>
  6.   <input type="submit" name="button1_get" value="GET">
  7.  
  8.   <form action="test.php" method=post>
  9.   <select name="req_post" id="req">
  10.          <option value="1">posted trips</option>
  11.          <option value="2">requested trips</option>
  12.   </select>
  13.   <input type="submit" name="button1_post" value="POST">
  14.  </FORM>
  15.  </form>
  16.  
test.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  print_r($_GET);
  3.  print_r($_POST);
  4.  
  5.  if(isset($_GET['button1_get'])==true)
  6.  {
  7.    echo $_GET['button1_get'];
  8.  }
  9.  else if(isset($_POST['button1_post'])==true)
  10.  {
  11.    echo $_POST['button1_post'];
  12.  }
  13. ?>
  14.  
save those code two different files according to name. then execute the htm file from your browser and test
Sep 18 '10 #7
i've got a little problem integrating the code into my code

Expand|Select|Wrap|Line Numbers
  1. if($search1 == '')
  2.    {
  3.       $smarty->assign('Error','Please enter any destination!');
  4.       $z=1;
  5.    }
  6.    elseif($type == 'like' && $status='1')
  7.      {
  8. $sql = "SELECT * FROM topic WHERE (Title LIKE '%$search1%') AND req= $req";
  9. }
  10.  
my html is
Expand|Select|Wrap|Line Numbers
  1. <select name="req" id="req">
  2.            <option value="1">yes</option>
  3.            <option value="2">no</option>
  4. </select>
  5.  
i am already putting the values into the database using this:
Expand|Select|Wrap|Line Numbers
  1. $sql = 'INSERT INTO topic (req) VALUES '." ('$_SESSION[EmpId]', $req)";
  2.  
let me see if i got the right idea on how I should implement the code

Expand|Select|Wrap|Line Numbers
  1. if($search1 == '')
  2.    {
  3.       $smarty->assign('Error','Please enter any destination!');
  4.       $z=1;
  5.    }
  6. if( $_POST['req'] == 1 || $_POST['req'] == 2 ) {
  7.      $req = (int) $_POST['req'];
  8. }
  9.    elseif($type == 'like' && $status='1')
  10.      {
  11. $sql = "SELECT * FROM topic WHERE (Title LIKE '%$search1%') AND req= $req";
  12. $req = 1;
  13. }
  14.  
what u think?
Sep 20 '10 #8
i found the answer

Expand|Select|Wrap|Line Numbers
  1. $req = intval ($_GET['req']);
  2. if($type == 'like' && $status='1' && $req > 0 && $req < 3)
  3. {
  4. $sql = "SELECT * FROM topic WHERE (Title LIKE '%$search1%') AND req= $req"";
  5. }
  6.  
Sep 22 '10 #9

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

Similar topics

4
by: Jean-Fran?ois Lacrampe | last post by:
Hello, I've been using QuickForm for a few months now and I am now given a new challenge: I've got a search form with a dozen of dropdown menus, the first dropdown menu being "Brand". If you...
5
by: michael | last post by:
How may the following script be modified to function with the list structure below it? In short: it is meant to apply a background style to groups of LI's and ULs depeding on the URL filename. ...
1
by: Mosher | last post by:
Hi all, I am looking for some event handler auto-calc help on a form that takes user input through text fields and dropdown menus. I would like some of the text fields to be auto populated when...
3
by: trint | last post by:
My boss wants this web app that I'm developing to have a java like dropdown menu. Is that possible with c# .Net? I haven't been able to find anything like that? Any help is appreciated. Thanks,...
2
by: Calvin KD | last post by:
Hi everyone, Can someone show me or point me in the right direction as how to create a "dropdown menu" which displays the menu items as a separete layer over the top of the contents of the page...
12
deephill
by: deephill | last post by:
hi i need form dependency. Can u check below code? <p>1. Are you married?</p> <p>
3
by: Ninio | last post by:
I have a simple form with a dropdown menu that consists of 3 option and each option should retrieve a query from a database. i have been looking all over the place and can't seem to find how to do...
1
by: uk0102 | last post by:
How to get value from cookie and set that as the selected in dropdown menu.I set the cookie when drop down menu (value) is changed and I need to get it and set as selected in dropdown menu??
1
SHOverine
by: SHOverine | last post by:
Recently my web host decided to "upgrade". This change rendered many of my pages useless and I am scrambling to fix the issues, so you may see several posts from me in the coming days. My first...
3
by: jerrydigital | last post by:
good evening, I am trying to allow my users to enter in text if they don't find their option on my drop down menu. In the code below, I can get a text box to show up when I select 'Other' on the...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.