Jump to content

SimpleXML Element & String Concatenation


bryank412

Recommended Posts

Hi guys,

 

It's been a long while since I've used PHP so I'm a bit rusty, been a

C# monkey as of late - but on to the problem at hand.

 

I have the following

<? php

#Convert the String Into XML
$xml = new SimpleXMLElement($_POST['name']);

#Itterate through the XML for the data
foreach($xml->vote as $vote)
{
        $foo .= $vote->teamID;

}

?>

 

And that does work it gets me all the values

 

But what I want to do is have something like

$query = "INSERT INTO table VALUES(";
foreach($xml->vote as $vote)
{
   $query .= $vote->teamID;
   $query .= ",";

}

$query = substr($query , 0 , -1);
$query .= ");";

mysqli->query($query);

 

But for some reason this just doesn't work; obviously I'm assuming

it's a syntax issue and I'm just an idiot; but some help would be

amazing

Link to comment
https://forums.phpfreaks.com/topic/94926-simplexml-element-string-concatenation/
Share on other sites

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.