Jump to content

[SOLVED] Select question


djtozz

Recommended Posts

Hi I'm having a problem with my search function

http://www.filemirrors.info/new/

 

I added the last selection box (for the filetype)

<select name="tmedia">
	<option value="all" <? if($_GET['tmedia']=='all') echo 'selected';?>>All</option>
	<option value="1" <? if($_GET['media']=="avi") echo 'selected';?>>avi</option>
	<option value="2" <? if($_GET['tmedia']=="mp3") echo 'selected';?>>mp3</option>
	<option value="4" <? if($_GET['tmedia']=="rar") echo 'selected';?>>rar</option>
	<option value="5" <? if($_GET['tmedia']=="zip") echo 'selected';?>>zip</option>
</select>

 

I've got a table called 'media' that contains the file extension (avi/mp3/exe..)

 

Now I tried following but I don't know how to put the extension (ex. avi) in that ????? field

 

if(!isset($_GET['type']) || $_GET['type']=="all") $fxtype=""; // part for selecting the file host = ok
else
{
	if($_GET['type']>=1 && $_GET['type']<=12) $fxtype="AND type='".$_GET['type']."'"; // part for selecting the file host = ok
	else $fxtype="";
}

if(!isset($_GET['tmedia']) || $_GET['tmedia']=="all") $fxmedia=""; // part for selecting the file extension = ok
else
{
	if($_GET['tmedia']>=1 && $_GET['tmedia']<=5) $fxmedia="AND media='??????"; // HereI need to get the extension name, and not a value
	else $fxmedia="";
}

$q="SELECT `...  FROM `v2links` WHERE  MATCH (caption) AGAINST ('$kwd') $fxtype $fxmedia ";

Link to comment
Share on other sites

Okay...just by chance, is it only avi's that aren't working?  Because you're using $_GET['tmedia'] for everything but avi's and $_GET['media'] for avi.

 

Otherwise, anything wrong with just using a case statement?

 

// Set fxtype
if( !isset($_GET['type']) || $_GET['type']=="all") $fxtype=""; // part for selecting the file host = ok
else 
{
      
      // part for selecting the file host = ok
      if ($_GET['type']>=1 && $_GET['type']<=12)  $fxtype="AND type='".$_GET['type']."'"; 
      else $fxtype="";
}

//Set fxmedia
if(!isset($_GET['tmedia']) || $_GET['tmedia']=="all") $fxmedia=""; // part for selecting the file extension = ok
else
{
      if($_GET['tmedia']>=1 && $_GET['tmedia']<=5)
      {
            $fxmedia="AND media='";
            switch ($_GET['tmedia']) 
            {
                  case 1:
                       $fxmedia .= "avi'";
                       break;
                  case 2:
                       $fxmedia .= "mp3'";
                       break;
                  {...etcetera...}
           }
      }
      else $fxmedia="";
   }

$q="SELECT `...  FROM `v2links` WHERE  MATCH (caption) AGAINST ('$kwd') $fxtype $fxmedia ";

 

 

 

Link to comment
Share on other sites

Hi

 

If the options are stored on a table with the number as a key then I would be keeping the number and linking to the table.

 

If not then I probably wouldn't bother with the number:-

 

<select name="tmedia">
<option value="all" <? if($_GET['tmedia']=='all') echo 'selected';?>>All</option>
<option value="avi" <? if($_GET['tmedia']=="avi") echo 'selected';?>>avi</option>
<option value="mp3" <? if($_GET['tmedia']=="mp3") echo 'selected';?>>mp3</option>
<option value="rar" <? if($_GET['tmedia']=="rar") echo 'selected';?>>rar</option>
<option value="zip" <? if($_GET['tmedia']=="zip") echo 'selected';?>>zip</option>
</select>

 

All the best

 

Keith

Link to comment
Share on other sites

Hi

 

If the options are stored on a table with the number as a key then I would be keeping the number and linking to the table.

 

If not then I probably wouldn't bother with the number:-

 

<select name="tmedia">
<option value="all" <? if($_GET['tmedia']=='all') echo 'selected';?>>All</option>
<option value="avi" <? if($_GET['tmedia']=="avi") echo 'selected';?>>avi</option>
<option value="mp3" <? if($_GET['tmedia']=="mp3") echo 'selected';?>>mp3</option>
<option value="rar" <? if($_GET['tmedia']=="rar") echo 'selected';?>>rar</option>
<option value="zip" <? if($_GET['tmedia']=="zip") echo 'selected';?>>zip</option>
</select>

 

All the best

 

Keith

 

Yeah, Keith's idea works too, but if you're insisting on separately validating the range (which incidentally you don't need to do because your selecting from a list of pre-defined values), you'll wind up back at a case statement again.

Link to comment
Share on other sites

which incidentally you don't need to do because your selecting from a list of pre-defined values

 

If your users are 100% honest people then you can take the predefined values as being OK.

 

But someone at some time is bound to try hacking with a dodgy value.

 

All the best

 

Keith

Link to comment
Share on other sites

If your users are 100% honest people then you can take the predefined values as being OK.

 

But someone at some time is bound to try hacking with a dodgy value.

 

All the best

 

Keith

 

Then going by number might be a better way to do it, since the validation of the range and the selection by case seem to make those things easier unless you can switch on a string value (I'm not sure if you can do that without looking it up).

Link to comment
Share on other sites

 

If the options are stored on a table with the number as a key then I would be keeping the number and linking to the table.

 

If not then I probably wouldn't bother with the number:-

 

Hey Guy's,

Thanks for the info, the values are not stored in a table, I used numbers because I didn't now for sure how to make difference between "all" and the file "extension"

 

if the value is a number, I could use

if($_GET['tmedia']>=1 && $_GET['tmedia']<=5)  $fxtype="AND media='".$_GET['tmedia']."'"; 

 

I'm not sure how to replace this.

Thanks

 

 

 

 

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.