Jump to content

Recommended Posts

flash is sending some variables to php.

$gameID = $_REQUEST['gameID'];//gets this as 1, 2 etc

$arr = $_GET['arr'];//gets this as i1=Symbol=Octopus222,Odds=2,Prize=puss&i2=Symbol=Lobster222,Odds=2,Prize=puss

 

i need to convert this to an array.

i tried $data = array($arr);

didn't work.

if i echo $data i get Array

 

 

Link to comment
https://forums.phpfreaks.com/topic/170298-how-do-i-convert-a-string-into-an-array/
Share on other sites

Like Daniel0 said

 

<?php
$arr = "i1=Symbol=Octopus222,Odds=2,Prize=puss&i2=Symbol=Lobster222,Odds=2,Prize=puss";  
$data = explode(",", $arr);
foreach($data as $k => $v) {
$data[$k] = explode("=", $v);
}
echo "<pre>";
print_r($data);
echo "</pre>";
?>

Matthew can you help me out here please. I'm going around in circles

 

i need to loop through the array and do an insert.

 

if there's an error i do an

echo '<?xml version="1.0"?>';

echo '<dataxml>';

die("There's little problem: ".mysql_error());

$MyError = "An error occured while saving data. Please try again later." + mysql_error();

echo "<sqlError>".$MyError."</sqlError>";

echo '</dataxml>';

 

once all the inserts are done i need to echo another bit of xml to say it's done.

 

currently the insert never happens and i'm not sure where to put the success message since it's in a loop and i end up with mailformed xml.

okay am i even remotely close (This gives me an <b>Warning</b>:  Invalid argument supplied for foreach() in <b>C:\xampp\htdocs\... error) when testing in browser

 

<?php

 

session_start();

include 'config.php';

include 'opendb.php';

 

$gameID = $_REQUEST['gameID'];

$arr = $_REQUEST['arr'];

 

$data = explode(",", $arr);

foreach($data as $k => $v) {

$data[$k] = explode("=", $v);

foreach($raw[$key] as $value){

$info = explode('=', $value);

$data[$key][$info['0']] = $info['1'];

}

}

echo '<?xml version="1.0"?>';

echo '<dataxml>';

if ( is_array( $data ) ){

$n = count($data);

for ( $i = 1; $i < $n; $i++ ){

$key = 'i'.$i;

// Read the various keys, you should know what to expect! //

if( !empty($data[$key]['Symbol'])){

$insert = mysql_query('INSERT INTO gameprizes(name, prize, odds, gameID) VALUES("'.$data[$key]['Symbol'].'","'.$data[$key]['Odds'].'", "'.$data[$key]['Prize'].'", "'.$gameID.'")');

}

}

}

if (!$insert) {

die("There's little problem: ".mysql_error());

$MyError = "An error occured while saving data. Please try again later." + mysql_error();

echo "<sqlError>".$MyError."</sqlError>";

} else {

echo '</dataxml>';

}

?>

 

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.