Link to home
Start Free TrialLog in
Avatar of gamebits
gamebitsFlag for Canada

asked on

How to break an array into individual variables

Here is the deal

I have a form where the user can select multiple items using checkboxes after the form is submited the script query the database (MySQL) and pull the data according to the checkboxes selected.

Here is the script to pull the data.

<?

                $section_id=array(); $section_id=$_POST['Record_id'];            

                     foreach($section_id as $value) {
                     
$query1 = mysql_query("SELECT street
                                    FROM City
                                    WHERE section_id = '$value'");
                         
 while($row2 = mysql_fetch_array($query1))
 
 echo "<p>".$row2['street']."";
  }
 
?>

The script works great and will echo all the streets on a different line as expected.

But what I need is to be able to break the array in individual parts and assign those parts to variables, so instead of getting something like

Majorstreet
Minorstreet
Sidestreet

I would get

$var1 = "Majorstreet";
$var2 = "Minorstreet";
$var3 = "Sidestreet";

Then I would be able to use the variables where I want in the display page.

Hope it make sense, should not be to hard for an Expert, an easy 500 pts. mostly because I'd like to get an answer asap.

Gamebits
ASKER CERTIFIED SOLUTION
Avatar of TeRReF
TeRReF
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gamebits

ASKER

TeRReF

Your solution did not work as is but you put me on the right track, thanks.

Here is the solution that worked for me.

<?
                $section_id=array(); $section_id=$_POST['Record_id'];            

                     foreach($section_id as $value) {
                     
$query1 = mysql_query("SELECT street
                                    FROM City
                                    WHERE section_id = '$value'");
                     
 while($row2 = mysql_fetch_array($query1))
 
$var[] = "".$row['street']."";

 $street1 = "$var[0]";
 $street2 = "$var[1]";

?>

Gamebits