patheticsam Posted January 12, 2009 Share Posted January 12, 2009 Hi! I have a multiple select box filled out with mySQL data...Is it possible a take the value of an entry and split this value into a couple a different variables? Here's the code so you can figure it out : <select name="select" size=5 multiple OnChange="window.location='?clt='+this.value"> <?php $db = mysql_connect('localhost', 'user', 'pass'); mysql_select_db('database',$db); $sql = "SELECT `field1`, `field2`, `field3`, `field4` FROM table"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['field3']." ".$row['field4']."\">".$row['field1']." ".$row['field2']."\n "; } ?> Basicly what I want to do is just split field3 and field4 into two different variables...Don't know if it's possible since i'm really new in php..Any help will be greatly appreciated!!!Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/140434-solved-help-needed-to-separate-a-value-into-different-variables/ Share on other sites More sharing options...
premiso Posted January 12, 2009 Share Posted January 12, 2009 What do you mean split those felds into different variables? When you post the form? Add a : inbetween them, then on form processing use split or explode it at : to put the different values into an array and access by index of 0 or 1. Quote Link to comment https://forums.phpfreaks.com/topic/140434-solved-help-needed-to-separate-a-value-into-different-variables/#findComment-735021 Share on other sites More sharing options...
patheticsam Posted January 12, 2009 Author Share Posted January 12, 2009 <select name="select" size=5 multiple OnChange="window.location='?clt='+this.value"> <-------Ast you can see as soon as I select something the page is reloaded and I can output the "clt" into a variable $variable = $_GET['clt'] <----------- Is it possible to split this variable into two different one since the variable comes from the value of the select box wich is "field4" & "field4".....I know I'm a newbie An exemple would be greatlu appreciated...Thanks!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/140434-solved-help-needed-to-separate-a-value-into-different-variables/#findComment-735308 Share on other sites More sharing options...
patheticsam Posted January 12, 2009 Author Share Posted January 12, 2009 I tried with : echo "<option value=\"".$row['field3']."/".$row['field4']."\">".$row['field1']." ".$row['field2']."\n "; $clt = $_GET['clt']; list($field3, $field4) = split('[/.-]',$clt); But it's not working... ..Does anyone have any ideas?? Quote Link to comment https://forums.phpfreaks.com/topic/140434-solved-help-needed-to-separate-a-value-into-different-variables/#findComment-735347 Share on other sites More sharing options...
patheticsam Posted January 12, 2009 Author Share Posted January 12, 2009 Nevermind I made it but thank you all! Quote Link to comment https://forums.phpfreaks.com/topic/140434-solved-help-needed-to-separate-a-value-into-different-variables/#findComment-735349 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.