Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




How To Use Selected Data In The Listbox For My Query..


I have a multiple select listbox and I pass the data using array in php. How can I use these records to my query, or in one select statement. For an example:

I have a listbox of item codes; the user selects an item code/s to view it's inventory. The selected itemcodes will be pass on php using array and these records will be used as a query or search items on my database.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Calculating The Selected Prices In A Listbox
I am wanting to know how I can add the all of the selected prices in a
listbox? I need to add the selected prices altogether. The listbox
should have only the names of the products. The listbox should be like
below:

How Can I Populate A Listbox With The Result Of Mysql Query?
I would like to populate a listbox with the result of a mySQL Query.

Multiple Select From Listbox And Execute A Sql Query Select Statement
Supposing i have a html form with 2 listbox and i name it status and resolution.

So it goes <select name='status[]'>... <select name='resolution[]'>

Then i have a another php page.
$status = $_POST['status'];
$resolution = $_POST['resolution'];

Now my question is, how do i do the sql query statement?

mysql_query("SELECT * from bugs where status=$status and resolution=$resolution");

The problem is, i select 3 options form the status listbox eg. new, closed, duplicate. And from the resolution, i chose fixed, invalid.

PHP/MySQL: Query Based On Selected Form Option
Using PHP and MySQL. Trying to put a list of categories into a drop down
select option of a form like:

<form name="form" action="<? print $_SERVER['PHP_SELF']?>" method="get">
<select name="subject">
<option value=""></option>
<option value="field1">Field 1</option>
<option value="field2">Field 2</option>
</select>

<input type="submit" name="Submit" />
</form>

Then I want to process it so the MySQL query gets done depending on what
was selected. I came up with this:

//connect to database
mysql_connect("$dbhost","$dbuser","$dbpass");
mysql_select_db("$dbase") or die("Unable to select database");

// Build SQL Query
if (isset($_GET['subject']))
{
switch($_GET['subject'])
{
case 'field1':
$query = "select * from tips where category = 'field1'";
break;
case 'field2':
$query = "select * from tips where text like 'field2' ";
break;
default:
echo 'No subject found'
}
}

$results=mysql_query($query);
$numrows=mysql_num_rows($results);

etc etc etc

But that switch doesn't seem to work. Anyone have a suggestion as to how
I can code this to do the MySQL query based on the subject?

Display All Or Selected Data Based On An IF Condition
I am trying to display all and selected data based on an IF condition. It will either execute all the data from the table or selected data based on category. well at least it is supposed too. I can take out the select * query and it will work but I need to use both.

And I want the page to load all the data from the table on reload or load and when someone selects the list box and hits submit it will only display the selected ones on a web page.  Its probably something simple but I cant see why I dont get any results to display. Code:

Make Selected Option Stay Selected In A Combo After Submit
I have 3 comboboxes, one for the day, other for the month and another one for the year. Every time i select a value for the three of them and press the "Submit" button, they reset to the default option. Anyway this can be solved?

Multiple Selected="selected" In A List.
I have a database with 1 to many and the many is a list with multiple
selects in a list. When I click on a master record I have as part of
my form the select statement for the multiple choice list. I want the
list to highlight the multiple chosen values. here is part of the
code.

$dresscat = specdresscat($dresstypeid); //this is the query to get the
values in the detail table
$drcatrow = pg_fetch_array($dresscat);// the array for the detail
table.
<select name="stages[]" multiple="multiple">
<?php
$allstages = allstages(); // this is a function to query my database
to get the value for the list.
while ($allstagerows=pg_fetch_array($allstages)) {
$eachstage= $allstagerows["stageid"];
$specstage= $drcatrow["stageid"]; // this is the point I need help
if ($specstage == $eachstage){ ?>
<option value=<?php echo $eachstage;?> selected="selected"><?php echo
allstagerows["stage"]?></option>
<?php }else{ ?>
<option value=<?php echo $eachstage;?>><?php echo
$allstagerows["stage"]?></option>
<?php
}
}
?>
</select>

Listbox Problem
I am using two listboxes with multiple selection.
I have moved the contents from the first list box to the
second list box. But I am not able to get the value from the second list box.

Listbox And Its Selection
im trying to create a webpage using mysql and php. im using the below code to populate a listbox with playernames held in my database. once i select a name; im trying to make the page gather the relevant information from that users details to be displayed on the same page.

for example if i select "MoFish" from the listbox, i want it to echo all MoFish's details in the page such as his:

"age"
"height"
"weight"

if i select "Berty" i want it to echo bertys details. how can i acheive this? Code:

Retaining Value In Listbox Array
i have designed an application that is a dynamic submission form. i
have text fields and listboxes. now i am able to retain the values of
the listboxes when i populate the listbox "manually"(single listbox)
like this...

<select name="title">
<option value="1"<?php if ($_POST['title'] == &#391;') { echo
'selected="selected"' } ?>></option>
<option value="Mr"<?php if ($_POST['title'] == 'Mr') { echo
'selected="selected"' } ?>>Mr</option>
<option value="Mrs"<?php if ($_POST['title'] == 'Mrs') { echo
'selected="selected"' } ?>>Mrs</option>
<option value="Mstr"<?php if ($_POST['title'] == 'Ms') { echo
'selected="selected"' } ?>>Ms</option>
</select>

Now this works flawlessly for example if the firstname text box is left
blank and the user clicks "send" then validation occurs and the value
in the "title" listbox is maintained and user is prompted to fix the
error. However this does not work when i use a listbox that is
dynamically generated in an array.

<select name="title[]" //note title[] = an array
of titles within the form
<option value="1"<?php if ($_POST['title'] == &#391;') { echo
'selected="selected"' } ?>></option>
<option value="Mr"<?php if ($_POST['title'] == 'Mr') { echo
'selected="selected"' } ?>>Mr</option>
<option value="Mrs"<?php if ($_POST['title'] == 'Mrs') { echo
'selected="selected"' } ?>>Mrs</option>
<option value="Mstr"<?php if ($_POST['title'] == 'Ms') { echo
'selected="selected"' } ?>>Ms</option>
</select>

But my text boxes work(retain value on POST in the case there is
invalid input on the form)
<input name="fname[]" type="text" value="<?php echo $firstname;?>"/>

i have tried a couple of scenarios and in my debugging i see that if i
chose the "Mr" option and 'echo' to see if it is POST'ed, it is.
However when the form reloads it reverts to the default empty value of
the listbox?

thought maybe something like
//code above
<option value="Mr"<?php if ($_POST['title'][$count] == &#391;') { echo
'selected="selected"' } ?>></option>
//code below
But nothing...So how to retain the value of the listbox?

How To Fetch Records In Div Listbox?
I found this code interesting and wish to use for my project, but i wondering how do i fetch records in this nested div tags. Code:

Determine Contents Of Listbox
How can I determine the values of a listbox, both unselected or
selected after submitting the form:

Code:

<select name="sel1" size="10" multiple="multiple">
<? PHP code populates listbox ?>
</select>

Do I have to use Javascript to determine the contents, like in the
pseudo code Javscript below. But how would you pass the Javascript
return value to PHP?

Code:

function listBoxContents(sel1)
{
var selLength1 = sel1.length;
var valuesPresent1 = new Array(sel1.length-1);
var i;
for(i=0; i<=selLength1-1; i++)
{
valuesPresent1[i]=sel1.options[i].valueOf();
}

return valuesPresent1;
}

File Listbox Of Directory
Is there anyway someone could provide code to a soultion i need here. Basically i have a directory of all these files uploaded, and i need some sort of way for a php file to list all the items in that directory somehow, it doesent need to be special, i just need them listed so my users can see what is uploaded into that directory.

Inserting Variables For Listbox
In this code I am trying to insert the variable $i as an option in the listbox. It isn't working yet. Code:

Query For Showing Data?
I am trying to learn fast and take it all in! I have set up the sql database and want the person when they click on the category link to be able to see each product in that categoer printed one after the other on the screen! Code:

Inserting Data From Query
I have a simple query

$sql = "SELECT * FROM siteusers";
$query = @mysql_query($sql,$connection) or die(mysql_error());
while ($row = mysql_fetch_array($query))
{
print $row['email'].'; ';
}
This basically produces something like;

email@domain.com; myname@domain.com;

How can I define these as a variable such as

$allemails;

So that I can insert it into a INSERT query.

And lastly, how can I remove the symbol ; from the last row returned.

Create Listbox Depending On Variable
I currently have a variable called $NumPlayers which contains a number between 4 and 8;

depending on this value; i would like to create this amount of listboxes on my page. For example if the value of $NumPlayers is 6;

I would like 6 listboxes to be displayed on the page with names such as "Lstbox1" "Lstbox2".

I'm a bit clueless where to start; and was hoping someone could point me in the right direction.

PHP MySQL Query Not Displaying Data
I am having some problems with a database query that I am trying to do.
I am trying to develop a way to search a database for an entry and
then edit the existing values. Upon submit, the new values are updated
in all corresponding tables (the function of the pages in question).
However, on the page that does the DB update, I also want to do some
checks on the data before performing the update.

Now, the problem that I am running into is that when I don't update the
primary key field (keyid) the page is running into the section where it
displays a message that the keyid already exists. This only happens
when the keyid on the previous page is not changed.

Upon troubleshooting the problem I found that the very first SELECT
statement does not seem to be returning any rows despite the fact that
the statement, when run on the SQL server, returns exactly one row. If
any could provide some assistance with this matter, I would be most
appreciative.

Code:
<?php
session_start();
header("Cache-control: private"); //IE 6 Fix

//continue if authenticated
if ($_SESSION['auth'] == 1)
{

//get variables from post
$keyid = $_POST['keyid'];
$username = $_POST['username'];
$corpid = $_POST['corpid'];
$usergroupname = $_POST['usergroupname'];
$oldkeyid = $_POST['oldkeyid'];
$oldcorpid = $_POST['oldcorpid'];
echo("Keyid: $keyid");

// Connect to MySQL
mysql_connect ("address.com", "user", "pass")
or die ('I cannot connect to the database because: ' .
mysql_error());
//select database on server
mysql_select_db ("seniorproject");

//SQL Statement
$sql = "SELECT keyid, corpid FROM users
WHERE keyid='".$keyid"'";

// Execute the query and put results in $result

$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );
echo mysql_result($result,0);

// Count number of matches and print to screen
$numrows = mysql_numrows( $result );
if ($numrows == 1)
{echo(" SQL Query: $sql");
$result_ar = mysql_fetch_row($result);
$result_ar = mysql_fetch_row($result);
$dbkeyid = $result_ar['keyid'];
$dbcorpid = $result_ar['corpid'];
echo("<br> CorpID: $corpid <br>");
echo(" DBCorpid: $dbcorpid <br>");
echo(" DBKeyID: $dbkeyid <br>");
if($dbcorpid == $oldcorpid)
{
//If this condition is true, then KEYID has not changed. Execute
code

// Formulate the query

$sql = "UPDATE users
SET corpid = '".$corpid."', username = '".$username."',
usergroup = '".$usergroupname."', keyid = '".$keyid."'
WHERE keyid = '".$oldkeyid."'";........

Using Session Data To Query A Database
Basically the title is the general idea of what i'm trying to do, a user logs in, great, his login id is stored (it is also his number on a seperate database) in a session variable. Now that session variable needs to be queried to another database (with all of that users information) to get all of the information on that user back to the original server (not the first database, the first database just has user number, id, and a password field).

So I have a  question, and if you have answers great! or if you know of the thread that they are on that would also help because i've been searching and haven't found anything yet.

1. How can I query a session variable in a sql statement, do I just put select * from users where '.$_SESSION['mysessionname'].' = usernumber ?

List All Images Filenames From Directory Into Listbox ?
I need to list all images filenames from specified directory into listbox with php (e.g. limiting to .jpg, .png, and .gif)? How do I do that?

Adding Multiple Listbox Items To Mysql
I want to be able to select multiple items from a listbox in a form and send the result to mysql blob. I only get one item to the bd. Here is part of the script.

Item: <select name="itm" align="bottom" multiple size="2">
<option value="item1">item1</option>
<option value="item2">item2</option>
<option value="item3">item3</option>
<option value="item4">item4</option>
<option value="item5">item5</option>
</select>
"Insert into xyz set itm = '$itm'";

Limiting/Structuring Query Data Output
Let's say I have a table called "customers" which will display many many results.
What I want to be able to do is output their names in a structured table when a query is presented. For example:

Customer 1, Customer 2, Customer 3, Customer 4
Customer 5, Customer 6, Customer 7, Customer 8

... where it will always revert to the next row after every 4 results, continuing as such.

Change Record When User Chooses Option From Listbox
I have a combobox which has different peoples names which are pulled from fields in a database. Can anybody please show me some code that will change the recordset so say for example there were two records in the DB with three bits of data name, number and telephonenumber:

John      10      01234567544
Frank     34      07883922332

and somebody selects john from the select box that in the two fields it shows 10 and 0123...

and 34, 078839..... if they select frank.

How To Display Data From Same Query On Diffrent Pages Using Next Link?
When i run query i am getting thousands of records and i am displayaing
a particular no. of records on a single page say 100 records then i put
a link to go on next page. when user clicks on next page the another
100 records will be displayes so should i need to run the query again
to get records from 100 to 200 records?

No Database Selected
what I've got it a simple system that includes pages the reference to which are in a database. This bit worked a treat. until i tried to put something that did some work in one of the included pages. PHP Code:

Selected Box Action
how to set the respond to action when user choose an option inside a <select></select> box? eg. when user select an option in the <select> box then php search for data inside mysql and then display the required data on the <input type=text>.

Php Dropdown - Selected?
i'm using this to pull information from a database and display it in a dropdown list. The problem is I am using the name code when I goto the "Update" page, but i'm not sure how to add the "selected" field, that way what ever I saved in the database will load.

Example: I goto add and it add's the "id" of 7 to the field, when I load the page again it auto's back to 1 instead of clicking in-to 7 as thats whats already there... = ) Code:

Remember Selected Value DropDown
I am attempting to have a drop down menu that displays url from 1 table called links the same table also contains a name for the url. i.e. google.com = name and http://www.google.com = url The value of just the url from links is stored in a separate table called users in a field named search after form is submitted by user. Everything Posts correctly except when go back to edit the record and submit the form the drop down box does not retain the value of what had been previously selected although it is the correct record until form is updated when whatever value is currently in the drop down list will update the record.

I know the code is doing exactly what it is told to do, because I have no functionality in it to recall the value from the field search in the users table. I don't know if it is something I would have to add to the array or option value. I can get it to work if it is all hard coded, but I am attempting not to do this. I am pretty new to php mysql and any help is greatly appreciated.

This is the code I am working with that came mostly from a tutorial. PHP Code:

How To Give A Value To Non Selected Checkbox
I would like to get a value for a non selected checkbox in a form.

Imagine my form contains :

<input type='checkbox' name='t[0]' value=&#391;'>
<input type='checkbox' name='t[1]' value=&#391;'>

When I analyse $t, if first checkbox is not selected and second is, I have :
$t[0] has no value. $t[1] equals 1
and count($t) equals 1

I would like to find a way to get :
$t[0] equals 0. $t[1] equals 1
and count($t) equals 2

Resize Only Selected Images
I have an image upload script that is resizing every image that a user uploads.
What I would like to do is have a check box added to the upload form that a user can check to resize the image if they want to or leave it unchecked to just upload the image.

So if the box is checked the original image gets uploaded and a resized image is created as well If the box is not checked just the original image uploaded. I tried adding a check box but every image still was resized - checked or not - Im assiming because it was in the foreach loop so I dont know what to do. Code:

PHP And A Pre-selected Option In A Form
I've got a little text editor thing on my site, and to open a file, you input the file name and choose the folder from a drop-down list and click the Open button. The default filename is "index" and that file keeps track of all the files contained in that folder. It works okay. What's annoying is that regardless of what folder you're messing around in, the drop down list always goes back to showing the default folder name as the page is reloaded. I want it to be preselected to the folder it's in.

It seems simple enough--the folder you're in is $_GET['dir']. But I've read some HTML form how-tos, and I can only see that you can preselect using the tabindex="" or selected attribute.

Radio Button Selected
What I wish to do is have a radio button pre-selected depending on what is pulled from the database.

For example if I had 2 radio buttons:

o Yes o No

One has the value 1 and the other has the value 0

If 1 is selected from the database then Yes is pre-selected, else 0 is pre-selected. How would I do this?

Setting Selected Option Using PHP
I have a drop down list which I want to be set to what was selected when the form is submitted. As the form is processed by the same page, it returns to the preset default. How would I go about making this selection box set the option selected on the next page?

Selected Value In Dropdown Dependent On Database Value
i need a way to make the selected value of a drop down dependend on a result from a database query. PHP Code:

Export MYSQL Selected Rows
Any ideas on how to export selected rows from a mysql table into a schema.sql file?

I want to use mysqldump --opt database table but I don't wanna dump the whole table only results of a select.

PHPMyAdmin does it but I need to do it in shell script code.

Get The Info Depending On The Selected Option
I have a page that is intendend to update a table field on DB i have a drop down menu wich displays all the position fields available on db and a text area where i will insert the new data.

now the problem: I'm using the query SELECT * FROM table WHERE position = $position
the $position is the choosen option from the drop down menu. then have echo "<textarea>$functions</textarea>" where it will show to me the present data available on DB after all this, i have another query UPDATE table SET functions = $functions WHERE position = $position

All is ok and working except the fact that he doesn't displays $functions
when selecting a option from the drop down menu?

1 Record In Database But 2 Records Were Selected?
i'm retrieving a record from database. below the record, i have a yes and no button, where i can let user click and then count the number of yes and no.

everything works fine, but when i start to click the yes or no button, my record ,becomes two records. i only have one record in my database, but two same record was displayed.
this is the code: PHP Code:

Selected Hyperlinks Activate PHP Script
I have a sitemap page with approximately 20 different pages listed on it, 10 of which are password protected, 10 of which are not. I want the 10 non password protected page links on my site map page to execute the following PHP command when they are clicked:

<?
session_unregister("CustomerID");
session_unregister("UserID");
session_unregister("FirstName");
session_unregister("AccessLevel");
session_destroy();
?>

How do I integrate this PHP function into the following code so that, when one of these links is clicked, the PHP script above is executed:

<li class="content_text"><a href="index.php">Home Page</a> - The home page for #*$! </li>
<li class="content_text"><a href="login.php">Login Page</a> - The login page for #*$! </li>

However, I don't want the PHP script to execute when a user clicks one of these links:

Set The Selected Text For Option Box Of A Menu..
Having major issues with this simple task, and I cant work out why its
not doing as it should/expected.

Basically, ive got a drop down box with the added bit of php:

<select name="title" id="title">
<?php
if($_SESSION['title'] != "") {
echo '<option value="'. $_SESSION['title'] .'"
selected="selected"></option>'
}
else {
echo "<option value="" selected></option>";
}
?>

<option>Mr</option>
<option>Mrs</option>
<option>Miss</option>
<option>Ms</option>
<option>Dr</option>
</select>

Basically, if the user submits a form, the title is stored in the
session, this works fine, and then when returned to the page, the value
should be filled in.

Yet, when they return to the page, there value they selected is not
shown in this box, instead, theres just a gap. The source seems
correct, and this is whats shown:

<select name="title" id="title">
<option value="Mr" selected="selected"></option>

Html Pre-selected List Box Scrolled
Is it possible to have a list box with a pre-selected value automatically scrolled to that value when the form is loaded? i.e. if the size of the list box is 3, and the 4th value is pre-selected, I want the list box to appear starting at the 4th value in the form.

Showing What Was Selected In Drop-down Menu
I'm trying to create a form where the user inputs data, i validate it with php, and if some of the input is missing or invalid then i print out errors with the form filled out with the information they entered/selected previously so they can change/add to it.

The problem I'm having is setting my drop down menus to be selected when the form is returned instead of returning their original state. The menu I have is named A ($A). Here's an example of what I'm doing that isn't working: PHP Code:

Keeping Select Option Value Selected
I'm trying to learn how to keep the value "selected" once a form is set to read the values and then f-write them (all within a loop). The part that's giving me a problem is the part which would return the value of the form as "selected". PHP Code:

Display Selected Record That Has Been Passed To URL
I have a page which can list all records from a table in my local database.

For each record that is displayed there is link next to it. When the link is
pressed another page opens up and the ID (automated primary key in my table)
of the record selected is passed to the URL.

So now the URL looks something like this:

http://localhost/Webpages/newpage.php?recordID=3

How do I display the details of the record that has been selected on this
new page?

Multiple Select Box With Selected Option ...
first of all I have three tables (tournament_game, umpire_game, umpires). Updating tournament_game umpires, each game may have from two to four umpires, and those umpires can work from one to n number of games, that's why I'm using connection table umpire_game. I'd like to get selected multiple select box of umpires in game, it could be two to four options, with all umpires listed as options example:

<select name=umpire_game[] size=10 multiple>
<option value=$umpire_id>$umpire_name</option>
<option value=$umpire_id selected>$umpire_name</option>
<option value=$umpire_id selected>$umpire_name</option>
<option value=$umpire_id>$umpire_name</option>
<option value=$umpire_id selected>$umpire_name</option>
<option value=$umpire_id selected>$umpire_name</option>

PHP Code:

How Do You Do Selected In A Multi-value List Box In A Form?
I am populating a list box from a dictionary table and then picking
muliple values to insert into a detail table. How do I get the list box
to have multiple selections highlighted when I pick one of the master
items?

Select Pictures And Show Selected
I need to make a webpage (php) where users can select some
excercises(with picture) out of 40, and then display a page with only
the selected excercises (with their picture) that you can print.

Display The Content That Is Selected From The Dropdow
what im trying to do is, i have a drop down that displays all the files that are in the directory when the page loads. when a item is selected from the drop down list i want that file to load in the text area but i cannot get it to work, can someone tell me what im doing wrong? Code:

How To Get Form To Remember Selected Option?
I am now trying to make a form remember which color (a select list) they selected before pressing any of the submit buttons. I entered this code into the form:

<select name="color">
<option value="red">red</option>
<option value="blue">blue</option>
</select>

The submit is a GET type. For example, if the user selects blue and then clicks on either one of the "submit" buttons, I want the form to remember/show the blue option. Right now the select list always goes back to red, the first choice. I tried doing a <?php echo $red; ?> and <?php echo $blue; ?> for the option value, but this does not work since the select list needs a value.

Select Option Stays Selected
I have a normal drop down menu:

<select name="status" class="db_list_text">
                    <option value="All" selected="selected">All</option>
                    <option value="True">Active</option>
                    <option value="False">Inactive</option>
                  </select>
The idea for this is for the user to select either true or false and then to click submit to find data that matches either one. The coding is in the same page so the form basically just reloads the page and grabbes whatever info is requested. How can I with PHP, make it that the dropdown stays on the selected option when the page is reloaded?


Copyright © 2005-08 www.BigResource.com, All rights reserved