Jump to content

multiple selection form with PHP.


donovan78

Recommended Posts

Hi, I am trying to process this search in a MySQL database of gps tracks by category , MySQL  table is that :

CREATE TABLE `geo_routes` (

`id` int(11) NOT NULL auto_increment,

`name` varchar(200) NOT NULL default '',

`author` varchar(80) NOT NULL default '',

`description` text NOT NULL,

`category` varchar(100) NOT NULL default '',

`property` int(11) NOT NULL default '0',

`time` int(11) NOT NULL default '0',

`downloads` int(8) NOT NULL default '0',

`visits` int(8) NOT NULL default '0',

PRIMARY KEY (`id`),

FULLTEXT KEY `search` (`name`,`description`)

) ENGINE=MyISAM AUTO_INCREMENT=56 DEFAULT CHARSET=latin1 AUTO_INCREMENT=56 ;

The  multiple  select  form  that  is  :

<form action="<?php echo GEO_URL_ROOT.'/index.php?s=category'; ?>" method="POST">

<select multiple name="category[]" style="width:150px;height:260px;">

<option value="motor bike">Motor Bike</option>

<option value="biking">Biking</option>

<option value="mountain bike">Mountain Bike</option>

<option value="trekking">Trekking</option>

<option value="runner">Runner</option>

<option value="off road">Off Road</option>

</select> <br /> <br />

<input type="submit" name="submit" value="Submit">

</form>

 

And  the  php  script  makes  the  MySQL  query  is  that  :

function getRouteByCat($cat)   {         
    if(!is_array($cat)) return false;                  
    $query = "SELECT * FROM geo_routes";             

    $filters = array();
   
    foreach ($cat as $c) {  
    $filters[] ="category LIKE '%".$this->escape($c)."%'";              
      }   

      $query.=   (empty($filters)?'':' WHERE '.implode(' AND ',$filters)).' ORDER BY id ASC';                     
      return $this -> query($query);      
    } 

 

I  need    to  select  the  routes  in  database  by  category    from this form : motor bike,biking,mountain bike,trekking, runner,off road however    the  front-end  displays    the categories  ALL together, grouped  but  not  selected  by  genre.   

    For  example , if  I  select  "trekking"  in  the  form,  this  variable  go  to this  script  , who  process  the  post  :

    index.php
<?

   elseif(!empty($_GET['s'])) {

        $cat = $_POST['category']; 

        $cat =$database->getRouteByCat($cat);  

        $category=$cat; 

       

    switch($_GET['s']) {

        case 'name':

            $order = 'name ASC';

            $title = 'Tours  and  Hotels';

            break;

              

                case 'category':

                        $order = '$category';

                        $order = 'category DESC';

            $title = 'Category';

            break;  

                 

        case 'top':

            $order = '(downloads*10 + visits) DESC';

            $title = ' Rating';

            break;

        default:

            $order = 'id DESC';

            $title = 'Last Routes';

    }
?>

I  don't  know  if  i  am  using  the  wrong  variable  because  the  php script  make  this : 

http://trekhotel.com/bina/index.php?s=category

    Thanks  for  some  help  or  suggestion  ! 

 

Link to comment
https://forums.phpfreaks.com/topic/202513-multiple-selection-form-with-php/
Share on other sites

Really  i  guess  this  variable  defined  twice  is  wrong however  i  change  now :


elseif(!empty($_GET['s'])) {
        $cat = $_POST['category']; 
        $cat =$database->getRouteByCat($cat);  
        $order=$cat; 
switch($_GET['s']) {
	case 'name':
		$order = 'name ASC';
		$title = 'Tours  and  Hotels';
		break;
              
                case 'category':
                        $order = 'category DESC';
		$title = 'Category';
		break;  

 

 

And  continues  listing  full  categories  NOT  filtering  by  each  kind  ,  if  you  understand  me ? 

         

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.