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
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 ? 

         

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.