-1

I am trying to fetch one array from an Oracle database and another from a MySQL database.

But the arrays I get back are in different formats, and I am not able to display them in an HTML table.

$result = $instance->prepare("SELECT * from dd ");
$result->execute();
while ($row = $result->fetchAll(PDO::FETCH_ASSOC))
{
    $rows2 = $row;
}
$array = oci_parse($conn, "SELECT * FROM DD");
oci_execute($array);
while($row=oci_fetch_array($array, OCI_ASSOC))
{
    $rows1 =$row;
}

print_r($rows1);
print_r($rows2);

$output = array_merge($rows1,$rows2);
print_r($output);

Here $instance and $conn are the respective connection variables.

The outputs I get after printing the two arrays are:

Array from Oracle:

Array ( [CLIENTID] => 2 [CLIENTNAME] => dsd [PHONENO] => 53556535 [ADDRESS] => Mumbai [ROUTE] => 4323 ) 

Array from MySQL:

Array ( [0] => Array ( [ClientId] => 3 [ClientName] => PQR [PhoneNo] => 786483744 [Address] => Pune [Route] => 3329 ) ) 

And after merging I get this array:

Array ( [CLIENTID] => 2 [CLIENTNAME] => dsd [PHONENO] => 53556535 [ADDRESS] => Mumbai [ROUTE] => 4323 [0] => Array ( [ClientId] => 3 [ClientName] => PQR [PhoneNo] => 786483744 [Address] => Pune [Route] => 3329 ) )

How do I print this in a table in HTML format?

VMAtm
  • 27,943
  • 17
  • 79
  • 125
Light yagami
  • 13
  • 1
  • 5

1 Answers1

0

You can not just merge two arrays in this case.try code below;

$all = array();

$all[] = $rows1;

foreach($rows2 as $k2=>$v2) {
     $new=array();
     $new['CLIENTID'] = $v2['ClientId'];
     $new['CLIENTNAME'] = $v2['ClientName'];
     $new['PHONENO'] = $v2['PhoneNo'];
     $new['ADDRESS'] = $v2['Address'];
     $new['ROUTE'] = $v2['Route'];
     $all[]=$new;
}

 $str='<table><tr><th>CLIENTID</th><th>CLIENTNAME</th><th>PHONENO</th><th>ADDRESS</th><th>ROUTE</th></tr>';
foreach($all as $arr) {
     $str.='<tr><td>'.$arr['CLIENTID'].'</td><td>'.$arr['CLIENTNAME'].'</td><td>'.$arr['PHONENO'].'</td><td>'.$arr['ADDRESS'].'</td><td>'.$arr['ROUTE'].'</td>';
}
$str.='</table>';

echo $str;

If $rows1 is an array-array like $rows2, you should iterate same loop for $rows1 also

Оzgur
  • 432
  • 2
  • 10
  • @ozgur i am only able to get last row from the oracle database's "DD" table and not the other values and getting all the values from mysql database values – Light yagami Apr 09 '17 at 15:04
  • and when i use $rows2[] in order to retrieve completed data it says Undefined index: CLIENTID Undefined index: CLIENTNAME Undefined index: PHONENO for all the attributes – Light yagami Apr 09 '17 at 15:12
  • @Lightyagami for oracle you should follow php oracle documentation http://php.net/manual/en/function.oci-parse.php to see rows2 data, you can use print_r($rows2); – Оzgur Apr 10 '17 at 01:26