Hi,
Using the following selection criteria, I am able to list the data from mysql db, but I would like to provide the following options for users: Select All Data, Select None. I am not sure if this is possiible. Any help would be greatly appreciated.
Here's my code - <h4>SEARCH</h4>
-
-
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method = "post" target = "right">
-
-
//1st DROPDOWN
-
-
Date<br>
-
<select size="1" name="search">
-
<?php
-
-
$con = mysql_connect("localhost","****","****");
-
if (!$con) {die('Database is down: ' . mysql_error());}
-
mysql_select_db("test",$con);
-
-
$query = ("select distinct date from **** order by date desc");
-
$result = mysql_query($query) or die(mysql_error());
-
while($row = mysql_fetch_array($result)){
-
echo "<option value=\"$row[date]\">$row[date]</option>";
-
}
-
?>
-
</select>
-
-
-
//2nd DROPDOWN
-
-
<br><br>
-
Product<br>
-
<select size="1" name="search1">
-
<?php
-
$con = mysql_connect("localhost","****","****");
-
if (!$con) {die('Database is down: ' . mysql_error());}
-
mysql_select_db("test",$con);
-
-
$query = ("select distinct productname from *** order by productname desc");
-
$result = mysql_query($query) or die(mysql_error());
-
while($row = mysql_fetch_array($result)){
-
//echo "<option value=\"$row[date]\">.$row[date].'</option>'";
-
echo "<option value=\"$row[productname]\">$row[productname]</option>";
-
}
-
?>
-
</select>
-
-
<input type="Submit" value="Submit" name="Submit">
-
</form>
-
-
-
-
//ASSINGING THE SELECTED FIELDS TO A VARIABLE
-
-
$search = empty($_POST['search'])? die ("ERROR: Enter Search Criteria") : mysql_escape_string($_POST['search']);
-
-
$search1 = empty($_POST['search1'])? die ("ERROR: Enter Search Criteria") : mysql_escape_string($_POST['search1']);
-
-
-
-
//QUERY
-
$query = "SELECT * FROM *** where date = '$search' and productname = '$search1' or die (mysql_error());
-
$result = mysql_query($query) or die (mysql_error());
-
$num = mysql_numrows($result);
-
-
mysql_close($connect);
//OUTPUT
***
7 2288 Dormilich 8,658
Recognized Expert Moderator Expert
of course this is possible. you can use for instance a dropdown field (or radios) to select a fixed SQL statement.
ex. - // HTML
-
<input type="radio" name="sql" value="1" checked>
-
<input type="radio" name="sql" value="2">
-
<input type="radio" name="sql" value="3">
- // PHP
-
$sql_type = (int) $_POST['sql'];
-
if (1 == $sql_type) // that's only one possibility
-
{
-
$sql = "SELECT * FROM mytable";
-
}
-
elseif (2 == $sql_type)
-
{
-
$sql = "SELECT `id` FROM mytable";
-
}
-
// etc.
Thanks a lot.
I am rewriting my code, I will post the results soon..
imm..I think I am making some mistakes..
I've modified my code as mentioned below--
... - <input type="radio" name="product[]" value="1" /> Select All <br>
-
<input type="radio" name="product[]" value="2" /> ProductName1 <br>
-
<input type="radio" name="product[]" value="3" /> ProductName2<br>
-
-
<input type="Submit" value="Submit" name="Submit">
-
</form>
-
..
-
..
-
-
$connect = mysql_connect($host,$user,$password) or die ("Unable to connect to host");
-
mysql_select_db($db) or die ("Unable to connect to database");
-
-
-
-
$sql_type = (int) $_POST['product'];
-
-
if (1 == $sql_type) // that's only one possibility
-
{
-
$prodcut = "SELECT distinct productname FROM mytable";
-
}
-
elseif (2 == $sql_type)
-
{
-
$sql = "SELECT productname FROM environment_performance WHERE productname='ProductName1'";
-
}
-
elseif (3 == $sql_type)
-
{
-
$sql = "SELECT productname FROM mytable WHERE productname='ProductName2'";
-
}
-
-
-
$query = "SELECT * FROM mytable where productname ='$product'" or die (mysql_error());
-
$result = mysql_query($query) or die (mysql_error());
-
$num = mysql_numrows($result);
-
-
mysql_close($connect);
-
-
//OUTPUT GOES HERE
Note: I can see only the value 2 so am not sure you know.
When users select - select all then the output should list all the column values where productname = ProductName1 and ProductName2
Any help would be really appriciated..Th anks agian!
Dormilich 8,658
Recognized Expert Moderator Expert
well, why don't you use the selected SQL? you set the query string $sql via form and in your query you use $query instead of $sql. and you should not name the radio boxes "product[]" (there is no need to use an array)
tip: in the if-elseif conditions, use an else block in case the input does not match any previous condition (this may be another SQL statement as well as an Exception (Error message)) - if (1 == $sql_type)
-
{ ... }
-
elseif (2 == $sql_type)
-
{ ... }
-
else
-
{
-
throw new Exception("Incorrect choice of the SQL query.");
-
}
note for the HTML: the text that belongs to an input element should be put into a label - <input type="radio" value="2" name="product" id="product2">
-
<label for="product2">ProductName 2</label>
Ok sure, Investigating.. .
Thanks again!
Hi,
I was able to select all or none by using the checkboxes as mentioned below.
<tr>
<td>
Product
</td>
<td>
<input type="checkbox" name="product[]" value="AP" />AP
<input type="checkbox" name="product[]" value="AR" />AR
<input type="checkbox" name="product[]" value="GL" />GL
<input type="checkbox" name="product[]" value="COM" />COM<br />
</td>
</tr>
$product_array = $_POST['product'];
//echo $product_array;
foreach ($product_array as $one_product) {
$source .= $one_product.", ";
}
$product = substr($source, 0, 100);
Thanks a lot.
I was able to get it working by your idea as well..
i.e - $sql_type = (int) $_POST['sql'];
-
if (1 == $sql_type) // that's only one possibility
-
{
-
$sql = "SELECT * FROM mytable";
-
}
-
elseif (2 == $sql_type)
-
{
-
$sql = "SELECT `id` FROM mytable";
-
}
Thanks again!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Joseph Barron |
last post by:
Here is a SIMPLE problem that I'm trying to solve.
It works in Netscape 6.2, but IE6 gives ""No such interface
supported."
Below are page1.htm and page2.htm .
In page1.htm, there are two dropdown lists. If you change the
selection of the left one (e.g. choose parentoption2), it
should open up page2.htm in a popup window.
|
by: Mark |
last post by:
I have two dropdown lists. Both have autopostback set to true. In both
dropdowns, when you select an item from the list, it redirects to the Value
property of the dropdown. Nothing fancy.
Let's say you select 1 of the items, and are properly redirected. You press
the back button. I have three servers providing two different
functionalities:
1. After pressing the back button, the item you selected in the dropdown is
still selected.
|
by: Paul |
last post by:
I have a dropdown list box and a button on a web form, the autopost back is
false for the dropdown list box and button. When the button is pushed the
selection in the dropdownlist box is lost, just wondering what is wrong.
Selected value is always 1 no matter what is selected in the dropdown list
box.
Private Sub btn_yes_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn_yes.Click
Dim s_origidval As String
|
by: Mike Collins |
last post by:
I cannot get the correct drop down list value from a drop down I have on my
web form. I get the initial value that was loaded in the list.
It was asked by someone else what the autopostback was set to...it is set to
false.
Can someone show me what I am doing wrong and tell me the correct way? Thank
you.
In the page load event, I am doing the following:
|
by: jung_h_park |
last post by:
From: jung_h_park@yahoo.com
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Dropdown List not retaining its SelectedValue
Date: Mon, 26 Jun 2006 21:02:57 -0700
Hello,
My dropdown list control does not retain its SelectedValue. Unless I
read the SelectedValue right after the control has been loaded,
populated, and assigned with its original value (and of course that is
| |
by: er1 |
last post by:
Hi all,
I have created a double dropdown list. Based on the first list selection, second list populates (this works fine). I have a submit button, which when clicked should run a select query based on the values selected on both the dropdown lists. But this part is not working. It picks up right value for the first dropdown list and always takes the FIRST value of the second dropdown list. I am not sure how to make it use the selected value...
|
by: yasodhai |
last post by:
Hi,
I used a dropdown control which is binded to a datagrid control. I
passed the values to the dropdownlist from the database using a
function as follows in the aspx itself.
<asp:DropDownList ID="FldType_add" Runat="server" DataSource='<
%#GetFieldType()%>' DataValueField="Type" DataTextField="Type" />
Oce the page is loaded all the values are added to the dropdown list.
But when I thought of getting the selected value from the...
|
by: Andrus |
last post by:
I'm using WinForms DataGridView
I need to make dropdown list wider that grid column width.
I tried the following code, but dropdown list widht is the same as column
width.
How to increase dropdown list width ?
Andrus.
To reproduce
|
by: fish919 |
last post by:
Hello All,
I am creating a date base in access. I want to create a dropdown list box that is connected to another dropdown list box.
You start with a dropdown list that has 5 choices and each of these choices will call another dropdown list box when one of the choices from the first gets selected. (I hope this makes sense)
All of this is being done on a single form.
I know how to make a (sub) dropdown list not seen before the action...
|
by: abhi3211 |
last post by:
i am using java inside java script page.
in that page i want to use two dropdown list.
in first dropdown list i am getting data from ms-access database.
in second dropdown list i want to get data according to selection made in first dropdown list and it will also come from ms-access database.(for example if i am selecting country as india in first dropdown list then in second dropdown list will show states of india)
the problem is that i...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |