0

I am trying to get datas from database and storing in multidimensional array and showing as XML format. However my code does not work. I think problem is SELECTing datas from database and storing in array part. Can you see my wrong.

Thank you,

<?php

include_once 'dbh.inc.php';

$DB = new Database(); 

$query = mysql_query("SELECT `employee_id`, `employee_fname`, 
                            `employee_lname`, `employee_department`,
                            `employee_dateOfBirth`, `car_status` 
                    FROM `employee"); 

while ( $row = mysql_fetch_array($query)) {
    # employeleri iki boyutlu arraye atıyoruz
    $employeesArray[$row['employee_id']] = array($row['employee_id'],
                                                $row['employee_fname'],
                                                $row['employee_lname'],
                                                $row['employee_department'],
                                                $row['employee_dateOfBirth'],
                                                $row['car_status']); 

}

$doc = new DOMDocument('1.0');
$employeeList = $doc->createElement("employeeList");
$doc ->appendChild($employeeList);
$employeeInfo = $doc->createElement("employeeInfo");
$employeeList->appendChild($employeeInfo);

foreach ($employeesArray as $employee_id => $employeeINF) {

    $id_ = $doc->createElement("id",$employeeINF[0]);
    $employeeInfo->appendChild($id_);

    $name_ = $doc->createElement("name",$employeeINF[1]);
    $employeeInfo->appendChild($name_);

    $lname_= $doc->createElement("lastname",$employeeINF[2]);
    $employeeInfo->appendChild($lname_);


    $dateOfBirth_= $doc->createElement("dateOfBirth",$employeeINF[3]);
    $employeeInfo->appendChild($dateOfBirth_);

    $department_= $doc->createElement("department",$employeeINF[4]);
    $employeeInfo->appendChild($department_);

    $car_= $doc->createElement("car",$employeeINF[5]);
    $employeeInfo->appendChild($car_);

}

header('content-type: text/xml'); //Dosya tipi xml diye belirttik

echo $doc ->saveXML();//xml i olusturuyoz
?>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
pflove
  • 25
  • 8
  • Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help **you debug your code** [Take a quick look at a coding standard](http://www.php-fig.org/psr/psr-2/) for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end. – RiggsFolly Jan 28 '18 at 15:33
  • Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[this happens](https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Jan 28 '18 at 15:36
  • I am very sorry, i tried my best at this time but editing is very complicated. Thank you – pflove Jan 28 '18 at 15:36

0 Answers0