Jump to content

Searching with Check Boxes?


Solarpitch

Recommended Posts

Hey guys,

 

I want to have a search on my page that will allow the user to select multiple search terms from a check box list. For example, if they were seaching for a mobile phone and the list was..

 

NETWORK

-------------

O2

Vodafone

T Mobile

Three

 

Ho can I determine which ones was selected so I can create a query for the database? If only O2 and Three were selected I'd want my query to be something like...

 


SELECT * FROM phones WHERE network = 'o2' || network = 'three'

 

Link to comment
https://forums.phpfreaks.com/topic/133784-searching-with-check-boxes/
Share on other sites

I see. Would my array to catch them looking something like...

 

<?php 

if(isset($_GET['02'])){$networks[] = "o2"}

if(isset($_GET['meteor'])){$networks[] = "meteor"}

if(isset($_GET['vodafone'])){$networks[] = "vodafone"}

?>

 

something like that anyway?

 

I tried it your way and I'm trying it this way but it just seems to keep printing ARRAY.

 

<?php

if(isset($_POST['o2'])){$network[] = "o2 = 'Yes' ||";}	
if(isset($_POST['meteor'])){$network[] = "meteor = 'Yes' ||"; }
if(isset($_POST['vodafone'])){$network[] = "vodafone = 'Yes'"; }


echo $sql = "SELECT * FROM phones WHERE ".$network."";

?>

 

Just echoed the sql to test and it prints..

 

SELECT * FROM phones WHERE Array

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.