Jump to content

[SOLVED] Help Needed to separate a value into different variables


patheticsam

Recommended Posts

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!

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.

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

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

Archived

This topic is now archived and is closed to further replies.

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