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
Share on other sites

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.