Cluster
Cluster

Reputation: 65

PHP - Display results from MySQL correctly

I was just wondering if there is a way to display this one after the other rather than first amounts than dates.

$apaidString = $apaid;
$daterString = $dater;
$apaidArray = explode(',', $apaidString);
$daterArray = explode(',', $daterString);

<?php foreach($apaidArray as $apaid_Array){
echo trim($apaid_Array,",").'<br>';}?>
<?php foreach($daterArray as $dater_Array){
echo trim($dater_Array,",").'<br>';}?>

This code will display:

50
60
10
11-11-2016
12-11-2016
14-11-2016

What i would need would be:

50 11-11-2016
60 12-11-2016
10 14-11-2016

I get the values from a MySQL.

Upvotes: 2

Views: 65

Answers (2)

Frankich
Frankich

Reputation: 852

i think you can do like this but i'm not sure that is the better way

foreach($apaidArray as $key_array => $apaid_Array)
{
    echo trim($apaid_Array,",").' '.trim($daterArray[$key_array],",") .'</br>';
}

output:

50 11-11-2016
60 12-11-2016
10 14-11-2016

instead of

foreach($apaidArray as $apaid_Array){
echo trim($apaid_Array,",").'<br>';}
foreach($daterArray as $dater_Array){
echo trim($dater_Array,",").'<br>';}

and you can do directly

$apaidArray = explode(',', $apaid);
$daterArray = explode(',', $dater);

instead of

$apaidString = $apaid;
$daterString = $dater;
$apaidArray = explode(',', $apaidString);
$daterArray = explode(',', $daterString);

Upvotes: 1

Walk both arrays at the same time :

<?php
$apaidString = "50,60,10";
$daterString = "11-11-2016,12-11-2016,14-11-2016";
$apaidArray = explode(',', $apaidString);
$daterArray = explode(',', $daterString);

for ( $i = 0; $i < count($apaidArray); $i++ )
{ echo $apaidArray[$i].'<br>';
  echo $daterArray[$i].'<br>';
}
?>

The result is:

50
11-11-2016
60
12-11-2016
10
14-11-2016

Upvotes: 1

Related Questions