djtozz Posted October 20, 2009 Share Posted October 20, 2009 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 "; Quote Link to comment Share on other sites More sharing options...
janusmccarthy Posted October 20, 2009 Share Posted October 20, 2009 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 "; Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 20, 2009 Share Posted October 20, 2009 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 Quote Link to comment Share on other sites More sharing options...
janusmccarthy Posted October 20, 2009 Share Posted October 20, 2009 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. Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 20, 2009 Share Posted October 20, 2009 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 Quote Link to comment Share on other sites More sharing options...
janusmccarthy Posted October 20, 2009 Share Posted October 20, 2009 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). Quote Link to comment Share on other sites More sharing options...
djtozz Posted October 20, 2009 Author Share Posted October 20, 2009 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 Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 20, 2009 Share Posted October 20, 2009 Hi Have an array:- $fred = array('avi','mp3','rar','zip'); Then just use in_array(). All the best Keith Quote Link to comment Share on other sites More sharing options...
djtozz Posted October 20, 2009 Author Share Posted October 20, 2009 Problem solved, Thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.