0

I'm currently working on a site that uses server side javascript to send the results of various options using Form Data and arrays as POST - for example:

brand[]=Max+Warehouse+&brand[]=Superstore&timing[]=All day&flavour[]=Orange&flavour[]=Cola&sweeteners[]=Sugar&sweeteners[]=Date&sweeteners[]=none&pageNumber=1&tableLength=25&sortDirection=sortDesc&sortedBy=best_sellers

to a php script then the php will search the database for results that match options checked but I'm not sure how to do this.

I'm pretty new to php/mysql and don't know how to run through what's being sent if more than one value of the same option is sent.

Thanks in advance for any help

Sergey
  • 394
  • 1
  • 12
noobie_woobie
  • 129
  • 11
  • 1
    Please read: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) and also [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) – M. Eriksson Jan 29 '18 at 16:17
  • `(column = 'value' OR column = 'value2' OR column = 'value3')` – GrumpyCrouton Jan 29 '18 at 16:18
  • Have you considered passing the data to your PHP server as a JSON formatted string? With that said, you have not given very much information about what your code looks like, what you are expecting, and what is happening. Without a good question how do you expect good answers? – kojow7 Jan 29 '18 at 16:39

2 Answers2

0

The data of your request will be available in php by using :

$_POST['your_variable_name'];

Since your post request has many values for a unique variable there will be an issue. At best for example

$_POST['brand']

will give you the last passed value for this variable in the query.

If you want to query on multiple brand values, you may consider to store them in different fields in your post request so your query looks like:

brand1%5B%5D=Max+Warehouse+&brand2%5B%5D=Superstore&...

and will be retrieved in php with:

$brand1 = $_POST['brand1'];
$brand2 = $_POST['brand2'];

which can be later on used in your sql query.

EDIT: a more elegant way would be to pass the values for a variable as an array as it is very well explained here

Sebastien D
  • 4,369
  • 4
  • 18
  • 46
  • I don't mind having brand1, brand2 etc but want the query to run quickly and there may be around a hundred different values sent, will that cause a problem? How would I go about getting the results from that? – noobie_woobie Jan 29 '18 at 16:59
  • Well, I think as suggested ahead that you should tell us more about your code. What would be your javascript? – Sebastien D Jan 29 '18 at 18:48
0

You can get the value of the variable in PHP using $_POST['your_variable_name'] using this get all the variables and apply one database query to get data that matches with this php variables.

Ms.KV
  • 214
  • 2
  • 10