Jump to content

Help needed with structuring a query after submit? Example Shown


Solarpitch

Recommended Posts

Hey Guys,

 

The below image is an example of the search on my site. Basically in this example, the user wants to search the phones table and return phones that are on the O2 or Meteor network, and that have a flip style.

 

I have 2 tables for this, networks and styles.

 

//networks
id      network       phone_id
1      o2               1
2      meteor         1
3      o2               2


//styles
id     style             phone_id
1     flip                1
2     touchscreen    2
3     slider             3

 

How can I tell what check boxes the user has selected, and then format a query for it. Even if I had the essentials I could do the rest myself.

 

See, the way I have it done there would need to be 3 queries..

 

1: to query networks

2: to query styles with the results returned from networks

3: to query the actual phones table to return the all the phones

 

phonefinderexamplegc0.jpg

w221.png

You can use a table join to do it with one query

 

example;

 

SELECT `mainphonetable`.`phone`, `networks`.`network`, `styles`.`style`
FROM `mainphonetable` 
INNER JOIN `networks` ON `mainphonetable`.`phone` = `networks`.`phone_id`
INNER JOIN `styles` ON`mainphonetable`.`phone` = `styles`.`phone_id`
WHERE `styles`.`style` = 'flip' AND `networks`.`network` = 'O2'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.