PHP - Mysql Query To Search Multiple Fields In One Table

Topic

Mysql Query To Search Multiple Fields In One Table

I want to have a search product feature, but I would like members to be able to search multiple fields in one go i.e. product_code, Product_name in one MySQL query.

The thing is, members have to be logged on, so the query must also only show results relating to that specific member, via the session[member_ID], my current query for listing products for that specific member is :

Code: [Select]$sql = "SELECT productId, productCode, image, name, price, stock_level FROM product_inventory WHERE memberr_ID = '" . $_SESSION['SESS_mem_ID'] . ";How would I change the above into a search query to search for productcode, productname and still only show results beloging to this member using the session data ?

Mysql Query To Search Multiple Fields In One Table

I want to have a search product feature, but I would like members to be able to search multiple fields in one go i.e. product_code, Product_name in one MySQL query.

The thing is, members have to be logged on, so the query must also only show results relating to that specific member, via the session[member_ID], my current query for listing products for that specific member is :

Code: [Select]$sql = "SELECT productId, productCode, image, name, price, stock_level FROM product_inventory WHERE memberr_ID = '" . $_SESSION['SESS_mem_ID'] . ";How would I change the above into a search query to search for productcode, productname and still only show results beloging to this member using the session data ?

I want to export these table to and spreadsheet (.xls) with some criteria

a form will assign which data will published at the spreadsheet with these criteria#all data can be exported from three tables#some column can be selected from three tables#some or all data can be selected from individual table

i've implement a script for this but it didn't meet my requirements. Can anyone help?

How To Query Multiple Search Pages

Hi guys, I have a php file that will go to a site and scrape the data I need. However this site is setup to use pagination so when I try to scrape all the players names I have to do separate queries to search each page. Is there a way to find out by using code how many pages there are and query all the pages at same time?

I use this code Code: [Select]<?php //first page

//turn error reporting on libxml_use_internal_errors(true);

//get data from this page$dom = new DOMDocument;$dom->loadHTMLFile('http://www.gametracker.com/server_info/76.73.3.42:1716/top_players/?searchipp=50#search');$xpath = new DOMXPath($dom);

// Get the total player count$rows2 = $xpath->query('//div[@class="block774"]/div');

// Get the rows from the search list$rows = $xpath->query('//table[@class="table_lst table_lst_spn"]/tr');

for ($i=1; $i<$rows->length-1; $i++) { $row = $rows->item($i);

// Get the columns for a row $cols = $row->getElementsByTagName('td');

// Get the player rank (1st column) echo 'Rank:'.trim($cols->item(0)->textContent).PHP_EOL;

// Get the player name (2nd column) echo 'Name:'.trim($cols->item(1)->textContent).PHP_EOL;

// Get the player score (3rd column, actually 4th but number 3 is hidden) echo 'Sco '.trim($cols->item(3)->textContent).PHP_EOL;

echo "<br />"; }?>

<?php //secondpage

//turn error reporting onlibxml_use_internal_errors(true);

//get data from this page$dom = new DOMDocument;$dom->loadHTMLFile('http://www.gametracker.com/server_info/76.73.3.42:1716/top_players/?searchipp=50&searchpge=2#search');$xpath = new DOMXPath($dom);

// Get the rows from the search list$rows = $xpath->query('//table[@class="table_lst table_lst_spn"]/tr');

for ($i=1; $i<$rows->length-1; $i++) { $row = $rows->item($i);

// Get the columns for a row $cols = $row->getElementsByTagName('td');

// Get the player rank (1st column) echo 'Rank:'.trim($cols->item(0)->textContent).PHP_EOL;

// Get the player name (2nd column) echo 'Name:'.trim($cols->item(1)->textContent).PHP_EOL;

Mysql Search Query

the query is--SELECT col3 FROM my_table WHERE col2=SELECT(MAX(col2) FROM my_table WHERE col4='A')

For some reason this is illegal, I can also not use a limit because the number of rows is not known a priori. I remember seeing some sort of redirection in some other forum but would appreciate a more explicit response.

Mysql Search Across Multiple Tables

Hi,So I'm trying to make a car rental project, and I need to show cars of a specific type, available in a specific period. I'm currently using this query: SELECT * FROM car, reservations WHERE car.car_id = reservations.carAND car.type = 1 AND reservations.reserved_from >= "2011-12-22" AND reservations.reserved_to <= "2012-12-20";

So this returns all the cars of the type 1 reserved in 2011-12-22 - 2012-12-20 period. So know that I know which cars are unavailable, how would you go ahead and pick out what's left?

Mysql Search Database With Multiple Columns

I have a search set up to search a table for the text entered in a textbox, I have two columns in the table, one with the first name of people, and the second with their last names, I am wondering how I can search both, so for instance:

Code: [Select]$query = mysql_query("SELECT * FROM users WHERE fname LIKE '%$find%' OR lname LIKE '%$find%'");But if I type both parts of the name it doesn't return anything. works fine if I just search for "Roger" OR "Smith".

Php Help With Multiple Choice For Search Page (mysql)

I have a multiple choice search page which asks visitors to select one or more choices before rendering the search results. It only works in items 1+2 are selected, or 1+2+3, or 1+2+3+4, or 1+2+3+4, etc...

I want to make it so that any combination of choices work. Example: Items 1+6 or 2+3+5 or 1+4+6 etc...

I have four hours to fix it before my client shows up and need help BADLY.

Anyone out there who can help? Whoever can help me... you are the best and I will have a special prayer for you tonight.

Search A Keyword In Multiple Tables From Mysql With Php

Not sure if this topic goes in here, it is related to PHP but also MySql, so if i'm on the wrong board sorry!

What i'm trying to do is search for a keyword in 5 different tables and return the keyword ID from the table that its in

The tables i'm trying to search are as follow

locationstatecountyregioncontinent

The "location" table has all the locations i.e cities and each row has the following columns:id | continent_id | country_id | state_id | region_id | city_name

The "state" table is set the the following:id | name

"county" table :id | name

"region" table:id | region

and "continent" table id | name

The way it works is the can search for any city or state or county or region or continent and ideally it should look into the five different tables and return the id of that table. So if the use searches for United States it will look for United States in all five tables, obviously it would find it in the "country" table so it should return that "id". The results are returned in "json format"

Below is the code i have:

Code: [Select]<?$input = $_GET['keyword'];$data = array();

/*

In this query i'm attempting to search in all databases, but i'm not sure if i'm doing this right. I'm not getting any results so i know something is wrong just don't know how to write it.

*/

$query = mysql_query("SELECT * FROM locations JOIN states ON states.id = locations.state_id JOIN countries ON countries.id=locations.country_id JOIN regions ON regions.region_id = locations.region_id JOIN continents ON continents.id=locations.continent_id WHERE name LIKE '$input%' OR state LIKE '$input%' OR region LIKE '$input%' OR country LIKE '$input%' OR continent LIKE '$input%'") or die(mysql_error());

/*

Here the values are added to to the $json array. The "value" should be the "id" from the table that the keyword matched. The 'name'Should be the name of the actual keyword. Again if they search for United States the "id" will come from the "countries" table and the "value"would come from the "countries" table as the name

Hi frds.............I have two tables named "registration" and "participation". Registration table have some columns like "LoginId", "email","contact no.", "Name" etc.and participation table have 2 column named "LoginId" and "EventId".Now if user enters EventId, I want to display the details like email,contact no. etc.I have a code but it not works properly.......If result have more than one row it only displays the email and contact no. of last one instead of all.Plzzzzzzzzz help anyone...................????????/

Multiple Table Query

Hi guys,I need your help!I have two tables "sp_users" and "sp_schools" in the same database. Now I want to add column "time" from "sp_schools" to a phpfile which displays "sp_users".The column "time" should be after column "update".

I made it upto here, but to get the second query and displayPlease help. I am devastated...

Multiple Query On Same Table

Hello
We have a database table that confirms the installations started and completed for our game... and I am looking to confirm how many installs start but never complete...
So, this is my current query...

SELECT description, ip from error_log where description like '%install%' order by ip;

Multiple Table Query

I am trying already for days to sort it out but does not work.My file "pback.php" displays the mysql table "sp_users". I want to add the columns "school_name" and "school_address" from another table "sp_schools" (same database) at the right end of the displayed table in "pback.php" (after the column update)I tried with leftjoin but it does not work.Please help me. I am getting really frustrated.Thank you...

Multiple Search Boxes Help W/php Script To Get Mysql Results

I have a simple (1 table, 14 fields) database. I'm using 9 separate search boxes from my search page :http://www.cinemaposter.com/database.htmlThere are currently 162 entries. Hitting "submit" throws them all out, same with valid input into any box, with the exception of "country" - example : entering "F" gives 20results; "PL" gives 34 results.Here's my code (to simplify, I only went down to the 4th box ('country' - the last and only one giving correct results). I'm one sorry newbie.... please help !Here's the code :------------------

Mysql Query To Update Multiple Columns At Once?

I made a small editing system for my news page, and I need to update three columns within my table "announcements" in the database. I tried a method of updating all of them with one MySQL query instead of using three as it just isn't neat. I've searched several methods via google and I've tried all of them, but just can't seem to get it to work. Is this MySQL query correct?

?>All the variables are passed from a HTML form with $_POST. I need the search to work like this: If there is a value in a form field then the query gets appended with that value but when it gets to the $search_commodity it needs to search the second table (qc_lots) and check for the results. Any results that match have to be matched to the results from the first table (qc_reports) and display (echo) only qc_reports that match to both tables. The only common field is the report_id on the qc_lots table and the id on the qc_reports table.

Mysql Query Order By Multiple Columns

I am loading notifications from a database table called "notifications" and I am having a little trouble getting them to order in the correct way.

my query I'm using right now:

Code: [Select]$query = mysql_query("SELECT B.* FROM (SELECT A.* FROM notifications A WHERE A.user_id='$session' AND A.from_id!='$session' ORDER BY A.id ASC ) AS B ORDER BY B.state ASC LIMIT 7");

this works well as far as showing the unread notifications on top, then the read notifications below, however it's not ordering the two sets by ID (which the id auto increments so the higher id number is the newest) from newest on top to the oldest on bottom, still keeping them separated by the unread on top, read on bottom (column name is state for showing whether they're read or not). The order the notifications are displaying by their ID is: