Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8152477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:43:34+00:00 2026-06-06T15:43:34+00:00

I am working on a project for a lecture at the university and I

  • 0

I am working on a project for a lecture at the university and I am searching for a solution for more than 2 weeks now, and I just can’t get it right.

We have a project where we need to generate specific JSON or XML files to visualize them later with for example D3 or Sigma.

We have a mysql database and all the code is in Javascript (as you can see with the libraries) and we use pho to get the data from the database and to get it in the right format. Here is an example xml file I tried to create with php (it’s a gexf-file for the visualization with Sigma, but it’s just the same as xml):

<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.2draft" version="1.2">
<meta lastmodifieddate="2009-03-20">
    <creator>Gexf.net</creator>
    <description>A hello world! file</description>
</meta>
<graph mode="static" defaultedgetype="directed">
    <nodes>
        <node id="0" label="Hello" />
        <node id="1" label="Word" />
    </nodes>
    <edges>
        <edge id="0" source="0" target="1" />
    </edges>
</graph>
</gexf>

And Here is my php code where I tried to create the xml:

    <?php

set_time_limit(500000000);

ini_set('memory_limit', '-1');

class XmlWriter2 {
var $xml;
var $indent;
var $stack = array();
function XmlWriter($indent = '  ') {
    $this->indent = $indent;
    $this->xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
}
function _indent() {
    for ($i = 0, $j = count($this->stack); $i < $j; $i++) {
        $this->xml .= $this->indent;
    }
}
function push($element, $attributes = array()) {
    $this->_indent();
    $this->xml .= '<'.$element;
    foreach ($attributes as $key => $value) {
        $this->xml .= ' '.$key.'="'.htmlentities($value).'"';
    }
    $this->xml .= ">\n";
    $this->stack[] = $element;
}
function element($element, $content, $attributes = array()) {
    $this->_indent();
    $this->xml .= '<'.$element;
    foreach ($attributes as $key => $value) {
        $this->xml .= ' '.$key.'="'.htmlentities($value).'"';
    }
   $this->xml .= '>'.htmlentities($content).'</'.$element.'>'."\n";
}
function emptyelement($element, $attributes = array()) {
    $this->_indent();
    $this->xml .= '<'.$element;
    foreach ($attributes as $key => $value) {
        $this->xml .= ' '.$key.'="'.htmlentities($value).'"';
    }
    $this->xml .= " />\n";
}
function pop() {
    $element = array_pop($this->stack);
    $this->_indent();
    $this->xml .= "</$element>\n";
}
function getXml() {
    return $this->xml;
}
}
/*
$xml = new XmlWriter2();
$array = array(
array('monkey', 'banana', 'Jim'),
array('hamster', 'apples', 'Kola'),
array('turtle', 'beans', 'Berty'),
);
$xml->push('zoo');
foreach ($array as $animal) {
$xml->push('animal', array('species' => $animal[0]));
$xml->element('name', $animal[2]);
$xml->element('food', $animal[1]);
$xml->pop();
}
$xml->pop();
print $xml->getXml();
<?xml version="1.0" encoding="utf-8"?>
<zoo>
  <animal species="monkey">
    <name>Jim</name>
    <food>banana</food>
  </animal>
  <animal species="hamster">
    <name>Kola</name>
    <food>apples</food>
  </animal>
  <animal species="turtle">
    <name>Berty</name>
    <food>beans</food>
  </animal>
</zoo>
*/

mysql_connect("127.0.0.1", "root", "manager") or die(mysql_error()); 

mysql_select_db("enrondata") or die(mysql_error()); 

$data1 = mysql_query("SELECT DISTINCT sId FROM mailToId WHERE date 
BETWEEN '01.06.2002' AND '30.06.2002' UNION SELECT DISTINCT rId FROM 
mailToId WHERE date BETWEEN '01.06.2002' AND '30.06.2002'") or die 
(mysql_error()); 

$data2 = mysql_query("SELECT sender, recipient, count(*) AS numMails 
FROM mailTo WHERE date BETWEEN '01.06.2002' AND '30.06.2002' GROUP 
BY sender, recipient") or die (mysql_error()); 

$users = array();
$id = 0;
while($tmpUsers = mysql_fetch_array($data1)){
$tmpArray['id'] = $tmpUsers['sId'];
$user = mysql_query("SELECT email FROM users WHERE id=".$tmpUsers['sId']);
while($tmpUser = mysql_fetch_array($user)){
    $tmpArray['email'] = $tmpUser['email'];
}
array_push($users, $tmpArray);
}
$xml = new XmlWriter2();
$xml->push('gexf', array('xmlns' => 'http://www.gexf.net/1.2draft" version="1.2'));
$xml->push('meta', array('lastmodifieddate' => '2009-03-20'));
    $xml->element('creator', 'Gexf.net');
    $xml->element('description', 'A hello world! file');
$xml->pop();
$xml->push('graph', array('mode' => 'static', 'defaultedgetype' => 'directed'));
    $xml->push('nodes');
        for($i = 0; $i < count($users); $i++){
            $xml->push('node', array('id' => $users['id'], 
'label' => $users['email']));$xml->pop();
    }
    $xml->pop();
    $xml->push('edges');
        while($tmp = mysql_fetch_array($data2)){
            $xml->push('edge', array('id' => id, 
'source' => $tmp['sender'], 'target' => $tmp['recipient'], 'weight' 
=> $tmp['numMails']));$xml->pop();
            $id++;
        }
    $xml->pop();
$xml->pop();
$xml->pop();
print $xml->getXml();
?>

And it works, the code is correct, but it takes hours. Really, even after 30min it is not finished doing all that. And I have no idea how to improve it and get it very fast. Or is there another possiblity to get the data from the mysql database in the right format without using php?

Please help me. My deadline is really close and I have no ideas and didn’t find anything on the web that fits my problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:43:35+00:00Added an answer on June 6, 2026 at 3:43 pm

    So you doing over 500 000 querys, that a big overhead,
    try just join in the email in the first query:

    /* puggan added left join email */
    $data1 = mysql_query("SELECT DISTINCT mailToId.sId, users.email FROM mailToId LEFT JOIN users ON (users.id = mailToId.sId) WHERE date BETWEEN '01.06.2002' AND '30.06.2002' UNION SELECT DISTINCT mailToId.rId, users.email FROM mailToId LEFT JOIN users ON (users.id = mailToId.rId) WHERE date BETWEEN '01.06.2002' AND '30.06.2002'") or die(mysql_error()); 
    
    $data2 = mysql_query("SELECT sender, recipient, count(*) AS numMails FROM mailTo WHERE date BETWEEN '01.06.2002' AND '30.06.2002' GROUP BY sender, recipient") or die (mysql_error()); 
    
    $users = array();
    $id = 0;
    
    while($tmpUsers = mysql_fetch_array($data1))
    {
        $tmpArray['id'] = $tmpUsers['sId'];
    
        /* Puggan added: */
        $tmpArray['email'] = $tmpUsers['email'];
    
        // $user = mysql_query("SELECT email FROM users WHERE id=".$tmpUsers['sId']);
        // while($tmpUser = mysql_fetch_array($user))
        // {
        //  $tmpArray['email'] = $tmpUser['email'];
        // }
        array_push($users, $tmpArray);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a working project that Im amending, it crashes after trying to use
I working on project and have problem with threading and update of UI. I
I have a working C2DM project, atm. I have me and my colleagues phones
I have a project working fine under MSVS 2010 SP1. I'm trying to convert
I am working on project and ran into an issue. Now I want to
I am working on project where I have the checkInternet method in one of
I compiled an fine working project (before compiled with 3.1.3) now with 3.2.1 Now
I have a working project with Symfony2. One of my bundles works well by
I have a working project, one of the screen is for example ViewController 1
I'm copying some objective c++ files over from another (working) project. I get no

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.