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




Multiple Select From Database Where Clause


I have a website with a database full of category names...I want to be able to chose lets say 5 of these categories and use a select from database clause where I could simply enter the category names I want to use but am not sure how I would go about doing it.

I can get the list to display just the Aprilia category using the code below:

$data1->q("SELECT * FROM categories WHERE cat_name = 'Aprilia' ORDER BY cat_name asc");

However...how could I get my site to display Aprilia, Ducati, Honda, Suzuki, Yamaha?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Select Query With WHERE Clause Doesn't Work Any Longer
I have a table in MYSQL that I'm trying to set up a search query on (so it can be searched for records by an author's name). I did it several weeks ago and then it worked, but now when I try to run the search it returns no records although I know they are there. To my knowledge nothing has changed in my PHP script. I checked everyhting repeatedly but must be blind to the error. It's driving my crazy since I know it worked fine at one time.

If anyone has the energy to take a look and offer their suggestions, it would be greatly appreciated. Here is my script. PS. I can add a record and view all the records through other scripts with no problem.

<?php # Script 11.6 - md_seaauthor.php
// This page searches titles by author.

// Set the page title and include the HTML header.
$page_title = 'Search Mother Daughter Bookclub by Author'
include_once ('header4.html');

require_once ('Connections/mysql_connect.php');
// Connect to the database.

$query = "SELECT * FROM mdbookclub WHERE author ='$author'";
$result = mysql_query ($query);
while ($row = mysql_fetch_array($result)) {
$md = $row['md_id'];
$title = stripslashes($row['title']);
$author = stripslashes($row['author']);
$f_author = stripslashes($row['f_author']);
$pub_year = stripslashes($row['pub_year']);
$call_number = ($row['call_number']);
$display_block .= "<p><strong>Author:</strong> $author <strong>Title:</strong> $title<br />
<strong>Publication year:</strong> $pub_year <br />
<strong>Call number:</strong> $call_number </p>";
}
?>

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.

SELECT Error: No Database Selectedin Query: SELECT * FROM Schedule
I got the above error message after reading FAQ #10 which applied to my first error. The thing is, I thought I had selected a database. This script is copied from a tutorial, and I'm just too new at this to spot my error. PHP Code:

Multiple Multiple Select Boxes
I'm looking to have multiple multiple-select-boxes on a page. But I
can only get the contents from the last selected value within a box,
via PHP. I've tried numerous methods. What am I doing wrong?

You can see ALL the values present in the url:
http://myserver/test.php?notify_use..._updcats=Update
e.g.......

Posting Multiple Select
I'm having a little problem, in my form, I have to select multiple lines in a 'select' field and post it for processing.

Now in the $_POST-variable, there is only the last selected item visible.

How can I post every selected line?

Multiple Select Box Question
I have a list box on my page which I dynamically populate from the database. My question is, if I allow people to have multiple selections from this, how would I retreive the selections that they have made? example:- if I name the select box "Jobs", would i be able to do something like:- PHP Code:

Getting Multiple Data From <select>
Can anyone give me a quick hint for this?

Say, I have: <SELECT NAME="opt3" SIZE="15" multiple>

Then I'd like to list the items selected...
echo $_POST["opt3"];
but this gives only the first one

how do I get the rest?

List Box Multiple Select
I am trying to create a drop down list that permits a person to select multiple items from the list and have the results posted on a results page. I am using Dreamerweaver MX, PHP and a MYSQL database. I was able to select multiple items but only the last selected item would be displayed. I tried to modify the list box code and now it returns nothing. Code:

Select Multiple & Mysql
What's the sql should look like to get all possible data when using multiple select,
such as: <select name="hostfield[]" multiple> PHP Code:

Select Multiple Code
need to be able to generate a multiple select in a form using php and then write the reults to a relation table between a resource table and a look-up table..i.e.

table 1 list of resources

table 2 list of options for element in table 1

table 3 a many to many resolution table between table 1 and table 2

I can do this if only one option is select from a drop down list, code below:

PHP Code:

Retrieve Multiple Select
How to retrieve multiple selected value from select component with multiple
attribute?

Select Multiple In A Form
When using select multiple in a form how do I retain the highlighting of the selected highlighted values after the form has been submitted?

<select name="cities[]" size="4" multiple="multiple" style="font: 8pt Verdana" id="cities_id">

Multiple Tick-box Select
I have a list and what I would like to do with this list is have a tick-box next to each one, so someone can select multiple things out of the list. Then, once they click "submit", it displays just the things they selected.

The list in the data is displayed from a database by repeating the rows, so if there are 3 rows, it displays it in a table repeating the <tr><td><?=$thing?></td></tr> until it ends.

I know how to do forms, just not how to post only the selected data, to display it on a different page.

Multiple SELECT COUNT()'s In One Query?
I'm creating a script that, fairly often throughout, I need to use a SELECT COUNT() query on two seperate tables - this seems to be slowing the script down quite a bit, and if the script remains this slow, it won't be of much use to me...which would be very bad!

Is there anyway to combine these two to grab the COUNT() value from both in one query?

Select From Multiple Tables In Db From A Newbie
I have a db with 34 tables with all the same feilds, and would like to select 1 columb from all these tables. Is this possible from a select query, if so a example would be great.

You may well ask why have i 34 tables all the same, but i thought is was a good idea to set out the tables as per my catagories when i was constructing them. But now i know i can do them all from 1 table with multiple fields.

PHP Handling Of Multiple Select Fields
If I have a select element of a form that have the MULTIPLE attribute with name="temp", what will the variable names be in the action page (POST)? Will the first one be $temp[1], second $temp[2] and so one? This does not appear to be the case.

Multiple Select Box Search Queries
I am trying to create an elegant query together with a multiple select box, tbl_level linked by a foreign key. Sample code below:

$sql = "SELECT DISTINCT Firstname,.... FROM .... ";

//conditional statement to determine whether WHERE clause is needed
if($_POST["FirstName"] != "" {
$sql .= "WHERE ";
if($_POST["Firstname"] != "") {
$sql .= "Firstname LIKE
"".addslashes($_POST["Firstname"]).""" }

//select box entries array Level

if($_POST["Level"] != ""){
$i=0;$query.="( ";
foreach ($_POST["Level"] as $val{
if ($i >0){$query.= " AND ";}
$query .= "tbl_level.LevelCatID LIKE $val ";
$i=1;}
$query.=" )";
$query.= " AND tbl_name.NameID = tbl_level.NameID"; }
//query database

I can't use this as only a single Level select selection works, if user selects more , I can' t search the Level column for 2nd input from the select box using this. I am trying to avoid too many calls to the database, As I have several multiple select options for user to input for searching.Am trying to call single complex query at the end of code.

How To Update Select Multiple Menu??
how can i update the select multiple menu?? PHP Code:

Form Processing - Select Multiple
I'm trying to process a form that contains a SELECT with the MULTIPLE qualifier, but PHP only seems to be receiving the last selected entry in the list rather than all selected entries.

I tried parsing as an array (because the HTML definition says it should pass key pairs) but that gives me a run-time error saying the appropriate named variable isn't an array.
I've tried submitting to a script that displays php_info and the _POST vars entry lists just the single value.

I know that SELECT MULTIPLE is rarely used, but has anybody tried this before and encountered similar problems. any pointers on how to retrieve all the selected options gratefully received.

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:

Retieving Data From Multiple Select
how can I insert data coming from a multiple select box knowing that I need
to insert other form fields at the same time.

<select name="auswahl[]" size="5" multiple>
<option value="bream">bream</option>
<option value="eel>eel</option>
<option value="pike>pike</option>
....
</select>

Multiple SELECT Queries Combined
I have several SELECT queries on a few of my webpages, and I have been told that the more query connections that are open the slower the server will run.

So firstly, is it possible to merge/combine 2 SELECT queries into a single query? Code:

Posting And Validating Multiple Select
i have a multiple drop down with five items.. If i select 2 or more items and post, only one item is posted to the db! How do I make it post all the fields I have selected? Code:

Changing From Single To Multiple Select
I have a poll script that I am in desperate need to let the users have more then one choice to the poll when they are voting...here is the original code below all i know is i have to change the type from radio to checkbox.. 

but other then that i'm totally lost, can anyone please give me the exact code i would need to change this I am still a real newbie as far as this stuff goes.. Code:

Mysql_query: Select From Multiple Fields
I'm writing a very basic search script. I have a form field where I want to accept both first and last names. In my database, the first and last names are in separate fields. I want the query to go through both fields and come up with results. Here is the PHP code so far (only searches first name):

$search = $_POST['search'];

$data = mysql_query("SELECT * FROM customers WHERE fname LIKE'%$search%'");

//Display results
while($result = mysql_fetch_array($data))
{
echo $result['fname'];
echo " ";
echo $result['lname'];
echo "<br>";
}

How can i change this around to perform the way I need?

Form: How To Read Array From Select-multiple
<form method="get">
<select name="users" multiple>
<option value="peter">peter</option>
<option value="paul">paul</option>
</select>
<input type="submit" value="select">
</form>

When I select both the string behind the URL is:

?users=peter&users=paul

How do I read BOTH variables?

Select And Display Multiple Queries / Results
Howdy all, i've been looking through various sites / tutorials and through this php book I have here to try figure out whats causing this problem but haven't had any luck yet.

The problem is that its displaying the Designation as the link url instead of the jcode. Hope i explained this well. Above this bit of code has calls the individual Catagorys, if theres data in that catagory it will display it with whats below. PHP Code:

Accessing The Contents Of A SELECT (multiple) Array?
Simple I would guess but since I've never used one of these I'm not sure how to get at it:

PHP Code:

<select name="chooseConcert" size=2 multiple>
<option value="Conversations">Conversations (September 12, 2002)</option>
<option value="Karla">Karla (various dates in October /Nov)</option>
</select>

I need to somehow determine (and print out) the contents if BOTH options are checked. I'm getting the contents using"

$HTTP_POST_VARS['chooseConcert']

I tried it once with both options checked and it only returned the second value. So what's the syntax?

Displaying Select Multiple Box And Using Mysql Join
i have an edit page where the query lists all the information from the database about a business. each business can have multiple types so i made a many-to-many database and now i need to be able to show all the types that are in the db for each business on the edit page. here is what i have so far but it's only selecting the last type of business in the result. PHP Code:

Insert Data From Multiple Select List
Am trying to insert data into a mysql database from a multiple select list. How would i do this? Code:

Retrieving Full Entry From Multiple Select List
I have a list box with multiple selects. I define the name as numList[]. I
get the values from

$picked = $_POST['numList'];

It retrieves values for all those selected.

If the entries are, say,
First
Second
Third

and the first and third are select then $picked[0] has "First" and
$picked[1] has "Third".
If, however, the entries are:

First one
Second one
Third one

Then the values are for $picked[0] and $picked[1] are "First" and "Third"
respecticely.
How do I retrieve the entire value and not just the first word?

Populating SELECT Multiple Form Field And Inserting Into Db
I have an update form where I'm trying to populate a SELECT multiple field with a list of 48 categories, from tbl work_cat. And show, as SELECTED, the one or many choices that the user had previously selected from the 48 categories which are stored in tbl cat_relations as $relation_cat.

Then allow the user to update their selections and update the database. But I can't get my form to work. First problem, I can't get the SELECT field on the form to show the categories, and then I don't know where to go from there. Below are my form page and my processing page. Code:

Showing Selected Items In A Multiple Select Menu
I have a form that has several multiple select menus. I would like to save the multiple selections but be able to show them as selected items when the form data is updated.

Database Value Select In Combo Box!
This function is intended to display the current database field value as selected.. along with other values as general options.

I can't figure out how to get it work. Help is appreciated!!

function retrieve_category()
{
$cat = mysql_query("SELECT category_id FROM category");
while ($current_row = mysql_fetch_row($cat))
{
$row = $current_row[0];
if ($row == $id)
{
printf("<option selected>%s</option>
",$current_row[0]);
}
else
{
printf("<option>%s</option>
",$current_row[0]);
}
}
}

Populating A Select Box From A Database
I have a subscription database that allows you to edit a subscribers data. For example, you enter a search term like "Bob" and it returns a list of everyone named Bob. You click the one you want and it goes to a subscriber detail page, where all of his data is populated to a form. You can directly edit this form and click save to overwrite it.

The only issue is the select boxes (drop downs) - say I have four options in the drop down box, red, blue, green and black. On my details page for bob I end up with five, I have those four PLUS whatever was saved for his color, so it shows up twice. If Bob is green, my select box looks like:

Green
Red
Blue
Green
Black

How can I make it so that Green only shows up once?

Select One Record From A Database
I am trying to select one record from a database. This databse has like 10 tables. I do not know which table this record is in. What php and mysql syntax would I use to accomplish this?

Randomly Select From Database?
this might seem like a stupid question, i should be able to do this. but on the front page of my site i want a thing to show a few users. but i dont want it to show the same people over and over. i want it to select different people each time. any ideas?

Selective Echoing And Database Select
I have written a search engine for business listings for the company I work for. Each listing is in a database, and that works fine. The problem though is two-fold.

The first part of the problem is that not all listings utilise every column of the database, and this leaves gaps when echoing the results. This is not what i had in mind, Any ideas/help would be appreciated.

The second part of the problem is related to the first in that there is a link for any listing that has a website, but not every listing has a website, so every listing having a "Visit our Site" link is impractical and shoddy. Also, i'm not sure how to echo the url from the database effectively in the first place.

Editing Mysql Database Row With Select Box
I have a small site, this small site has a few categories, now I can add items through my online admin area fine and delete them fine, but when it comes to editting them I am having some trouble, everything is working fine except the category column, because it is a drop down box I do not know how to have the category selected during the creation progress selected all the other info is loaded.

Using PHP And MYSQL To Select From Database Using Images
I'm trying to update a main page with a list of details matching a selection from a display of images that are displayed in a small window that have been selected from an image group using a select box in the main window, however I don't know how to do this and the main page is not receiving anything when clicking on an image so it's refreshing with empty data. 

I've seen many many pages giving examples of how to do this with select boxes or how to do this if only one entry uses an image shown in the small window, but the image display window is displaying many different small images not a select box and the database itself has multiple entries that use the same image.  Can anyone help?  I have a few instant chat programs if someone wishes to discuss this with me in real-time to see what it is I'm trying to achieve.

Tick Box, Select And Update Database.
I am trying to change the value in table with a tick box. If the tick box is selected it changes the value in the field to 'y' and if it is not selected it changes the field to 'n'.

First of all I need to bring back the current state of the field and then I need to be able to update it from 'y' to 'n' as many times as I want. Code:

Population Select Menu Using Php And Database Values
I have no idea how to go about this. so i would apreciate some help i want to populate the values in a html select menu from database values in one table

so i want all the values from 1 particular field in the database to be displayed in the select menu as separate options.

Displaying A List Of Categories From A Database In A Select Box
Could someone please tell me why this outputs nothing

<select name=categories>
<?
$cat_array = get_categories();
foreach($cat_array as $this_cat)
{
echo "<option value="";
echo $this_cat["category_id"];
echo """;
echo ">";
echo $this_cat["category_name"];
echo "
";
}
?>
</select>

==========================================================

function get_categories()
{
//get the list of categories from the database

$conn = mysql_pconnect("localhost", "user", "pwd");
$query = "select * from categories";
$result = mysql_query($query);
if(!$result)
return false;

$num_cats = mysql_num_rows($result);
if($num_cats == 0)
return false;

$result = db_result_to_array($result);
return $result;
}

//A function that returns a query to the database as an array
function db_result_to_array($result)
{
$res_array = array();
for($count=0; $row=@mysql_fetch_array($result); $count++)
$res_array[$count] = $row;

return $res_array;
}

Connecting Two Database Populated Select Menus
I am able to grab the data from the database to populate the menus individually using.
PHP Code:

Select Specific Phrase From MYSQL Database
I am working on a World of Warcraft guild's website and I am trying to create a page where players can select different kinds of gear, i.e. the gear with the most Stamina.

All the player's items are stored in the database and every item have a field in the Items-table containing the item's tooltip. This could look something like:

Boots of the Nexus Warden
Soulbound
Feet Cloth
97 Armor
+27 Stamina
+17 Intellect
Durability 35 / 35
Equip: Improves spell hit rating by 18.
Equip: Increases damage and healing done by magical spells and effects by up to 21.

I then want to select the item with i.e. the most Stamina for all the different slots; Head, Chest, Legs etc.

If I write this:
$query = mysql_query("SELECT substring(item_tooltip, LOCATE('Stamina', item_tooltip)) AS maxor FROM roster_items WHERE member_id = &#3962;'") or die(mysql_error());

It returns the following:
Stamina +17 Intellect Durability 35 / 35 Equip: Improves spell hit rating by 18. Equip: Increases damage and healing done by magical spells and effects by up to 21.

But I want for it to show the leading characters also (in this case "+27 " before "Stamina") and then not show anything else after the phrase "Stamina". So it shows "+27 Stamina" and nothing else for the above mentioned item. How do I accomplish this?

And then, secondly how do I then get it to show only the item with the most Stamina after it selected the above?

Hope this makes any sense.

I've tried to search these forums and found something a little along the lines of my problem but haven't been able to adjust them to my needs and I therefore need your help which will be greatly appreciated.

Reusing An Object For Common Select To Database
I've noticed that after I finished this app, I had repeated a similar task over and over and would like to modularize it. The repeated task was connecting to the database, executing a select, putting all the results of the columns into different variables of an object. PHP Code:

Simple Filter Of Database With $_GET And Select SQL
I need help with my logic statement with a simple search engine on a MySQL table.
I have three form text input fields named f_name, l_name and dept. I am using the GET method to gather data the user enters in each input field.

So far I have been able to build a check to see that the submit has been clicked but I am having trouble with assembling the SQL statement because I need for the search engine to be able to filter the results based on the information provided in 1-3 of the fields.

I could use if statements with some and clauses but that would mean that I would have to account for each combination. Something like

If(($_GET[‘f_name’] != “”) || ($_GET[‘l_name’] !=) || ($_GET[‘dept] !=)){

$sql = "SELECT * FROM facform WHERE f_name LIKE '$_GET[f_name]',
l_name LIKE '$_GET[‘l_name]', dept LIKE '$_GET[dept]' ”;}

The problem with this is that I would have to get every combination and it’s not very scalable. How can I create this SQL statement dynamically? Code:

Error In Generating Table From Database Select Statment
I am trying to dynamically create a table with the results from a select statement. Below is the code that is not working. Any help would be oh so greatly appreciated. This is for a final at school which is due in an hour. This is the only thing I can't seem to make work. Code:

Select Specific Snippet Of Text, Replace With A Database Result
I'm having some problems trying to do something; I just can't think of a way to do it. Basically, I want to search for a specific snippet of text in a body of text, then replace it with the requested database result with some thrown in HTML.

Users will be able to type the following (or something along these lines, depending on what works best): [image=12345]Insert caption here[/image]

Then I need it to search for the requested image in the appropriate table and return the image's url (for an example, let's say the table is called "images", and the columns required are "imageid" and "imageurl". Code:


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