Jump to content

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


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

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.