Link to home
Start Free TrialLog in
Avatar of EzEApostle
EzEApostle

asked on

Inserting a single DB line within a foreach statement

Hi Experts,
I have a form where members can upload a file, I have created a parser to grab the information from the file perfectly. My problem is, my data is currently being displayed via a foreach statement (code in below snippet).

Rather than echoing the data to the screen, I want to save the data in my database as a single line only to save from having to process the file each time. If I put an insert within the foreach statement its obviously going to create more than 1 DB insert.

The values being displayed on the page here is what i need to catch in a single statement:-
echo 'player with no team: <br />';
echo 'player in team '.$k.'<br />';
echo 'Player Name:'.$player['name'].'; IP: '.$player['ip'].'; Army: '.$n->getArmyName($player['army']).'

Can anyone help?
Thanks in advance
$n = new $classname();
    if (!$n->parse($_FILES['some_identifier']['tmp_name'])) {
        die('can not read it somehow');
    }
    $teams = $n->getTeams();
    foreach($teams as $k => $team) {
        if ($k == 0) { // team 0 store the player without team
            echo 'player with no team: <br />';
        } else {
            echo 'player in team '.$k.'<br />';
        }
        foreach ($team as $k_p => $player) {
            echo 'Player Name:'.$player['name'].'; IP: '.$player['ip'].'; Army: '.$n->getArmyName($player['army']).'<br />';
        }

Open in new window

Avatar of QualitySoftwareDevelopment
QualitySoftwareDevelopment

You can make it as this (if I get the meaning right ;-))


$sql="INSERT INTO table_name (field1, field2, field3) VALUES (";
 
//make your first datacollect
$sql.=$datacollect.", ";
 
//make your second datacollect
$sql.=$datacollect.", ";
 
//make your third datacollect
$sql.=$datacollect."); ";

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of QualitySoftwareDevelopment
QualitySoftwareDevelopment

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