Minase Posted August 24, 2008 Share Posted August 24, 2008 hy there i do have a dropdown <select name="test" size=1> <option value="2">123</option> <option value="3">test</option> <option value="4">something</option> and a variable $a. i want if variable $a == 4 then the dropdown box to have the selected input 4. and another problem if $b = "abcd"; i want to search in this variable for values like if $b has "a" than $a1 = 1; hope you understand thanks Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/ Share on other sites More sharing options...
DeanWhitehouse Posted August 24, 2008 Share Posted August 24, 2008 <option selected="selected" value="<?php echo $a; ?>"><?php echo $a; ?></option> Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624371 Share on other sites More sharing options...
Minase Posted August 24, 2008 Author Share Posted August 24, 2008 you did not understand me if $a == 4 then the option number 4 to be selected. Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624384 Share on other sites More sharing options...
DeanWhitehouse Posted August 24, 2008 Share Posted August 24, 2008 Yes i did understand you, i have shown you how to make something selected, i am not writing it all for you. Please try your self. All you need to do is add an if statment. There are two ways , first: <option selected="selected" value="<?php if($a == 4) echo 4; ?>"><?php if($a == 4) echo 4; ?></option> second: <option value="2" <?php if($a == 2) echo "selected='selected'";?>>123</option> <option value="3" <?php if($a == 3) echo "selected='selected'";?>>test</option> <option value="4" <?php if($a == 4) echo "selected='selected'";?>>something</option> Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624387 Share on other sites More sharing options...
Minase Posted August 24, 2008 Author Share Posted August 24, 2008 thank you very much but how can i check if a variable contain some values? like in my first post?thanks Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624389 Share on other sites More sharing options...
DeanWhitehouse Posted August 24, 2008 Share Posted August 24, 2008 this may do it http://uk3.php.net/manual/en/function.stristr.php Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624390 Share on other sites More sharing options...
Minase Posted August 24, 2008 Author Share Posted August 24, 2008 that doesnt help very much i will explain what i must do. i must put every character of the string into variables. every character into its own variable. thanks Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624408 Share on other sites More sharing options...
Minase Posted August 25, 2008 Author Share Posted August 25, 2008 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624800 Share on other sites More sharing options...
peuge Posted August 25, 2008 Share Posted August 25, 2008 To check if a variable contains some values try using http://www.php.net/preg_match Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624855 Share on other sites More sharing options...
Minase Posted August 25, 2008 Author Share Posted August 25, 2008 maybe someone have a better ideea how to do this .let me explain: i do have a variable $access $access = "1234567"; and 7 checkboxes with name from 1-7 i want if the variable contain 134 the checkboxes with name 1,3,4 to be checked. but i cant figure out what is the best method i was thinking to split those numbers and use an if statement,but i cant make it to split so anyone has ideeas? thanks Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624862 Share on other sites More sharing options...
Lamez Posted August 25, 2008 Share Posted August 25, 2008 <?php if ($a == (4)){ $a = "selected"; }else{ $a = ""; } ?> <select name="test" size=1> <option value="2">123</option> <option value="3">test</option> <option <?php echo $a; ?> value="4">something</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624866 Share on other sites More sharing options...
Minase Posted August 25, 2008 Author Share Posted August 25, 2008 your code is easy if it was just 1 checkbox no problem but they are seven and it can be combinated.... Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624867 Share on other sites More sharing options...
DeanWhitehouse Posted August 25, 2008 Share Posted August 25, 2008 you have to try and do it on your own, not expect us to write it all for you. Go on what we have given you , and try to figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624892 Share on other sites More sharing options...
Minase Posted August 25, 2008 Author Share Posted August 25, 2008 all of posted method in this thread i did know,i dont need the code i need the structure the ideea how to do it code is easy to write,but i dont have the ideea.... Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624895 Share on other sites More sharing options...
DeanWhitehouse Posted August 25, 2008 Share Posted August 25, 2008 And we have given it all in this thread. edit: look through here for an answer to your second question http://uk3.php.net/strings Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624896 Share on other sites More sharing options...
Minase Posted August 25, 2008 Author Share Posted August 25, 2008 thank you for all your help i will let this topic unsolved maybe someone will reply with a better answer Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624926 Share on other sites More sharing options...
DeanWhitehouse Posted August 25, 2008 Share Posted August 25, 2008 We have given you everything use preg_match for question 2 , and question one has been anwsered three times. Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624929 Share on other sites More sharing options...
Minase Posted August 25, 2008 Author Share Posted August 25, 2008 about question nr 2 i did reply all time lol Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624935 Share on other sites More sharing options...
DeanWhitehouse Posted August 25, 2008 Share Posted August 25, 2008 Then the topic is solved unless you have another question Quote Link to comment https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/#findComment-624937 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.