I am using an API from Bittrex , reading the json and then looping through with a for each loop to get the info i need
everything is working correctly. and here is the code :
foreach($return[result] as $x=>$x_value){
extract($x_value);
echo $OrderUuid." " .$closedDate ." " .$closedTime ." " .$Quantity." " .$Price." " . $PricePerUnit * 100000000 ." <br>";
}
But, What I want to do because I am putting this into a table with pagination is I need to be able to only echo out results like 1-5 then next page will be 6-11 and so on
i know the count already by using this and it returns the amount of results.
$thisManyResults=count($return[result]);
I know i need to keep in mind that index starts at ZERO as well.
Loops confuse me so badly, please also give an explanation for a newbie to wrap his head around. Thank you
EDIT:
foreach($return[result] as $x=>$x_value){
extract($x_value);
$str66 = str_replace('T', ' ', $TimeStamp);
$newarray = explode(" ", $str66);
$date =date_create($newarray[0]);
$closedDate = date_format($date,"m/d/Y");
$closedTime = date("g:i:s a", strtotime($newarray[1]));
// echo $OrderUuid." " .$closedDate ." " .$closedTime ." " .$Quantity." " .$Price." " . $PricePerUnit * 100000000 ." <br>";
echo "<td style='text-decoration:none;color:#000000;font-weight:normal'>". $Quantity ." </td>";
echo "<td style='text-decoration:none;color:#000000;font-weight:normal'><center>". $Price." </center></td>";
echo "<td style='text-decoration:none;color:#000000;font-weight:normal'><center>". $PricePerUnit * 100000000 ." </center></td>";
echo "<td style='text-decoration:none;color:#000000;font-weight:normal'><center>". $closedDate." </center></td>";
echo "<td style='text-decoration:none;color:#000000;font-weight:normal'><center>". $closedTime." </center></td></tr>";
}
but this shows ALL results 0-22 (23 results) I need to be able to only show in table 0 thru 5 or 6 thru 10
here is the final code in case someone else can be helped
$start="0";
$end ="8";
foreach (array_slice($return[result], $start ,$end ) as $x=>$x_value) {
extract($x_value);
$str66 = str_replace('T', ' ', $TimeStamp);
$newarray = explode(" ", $str66);
$date =date_create($newarray[0]);
$closedDate = date_format($date,"m/d/Y");
$closedTime = date("g:i:s a", strtotime($newarray[1]));
echo "<td style='text-decoration:none;color:#000000;font-weight:normal'>". $Quantity ." </td>";
echo "<td style='text-decoration:none;color:#000000;font-weight:normal'><center>". $Price." </center></td>";
echo "<td style='text-decoration:none;color:#000000;font-weight:normal'><center>". $PricePerUnit * 100000000 ." </center></td>";
echo "<td style='text-decoration:none;color:#000000;font-weight:normal'><center>". $closedDate." </center></td>";
echo "<td style='text-decoration:none;color:#000000;font-weight:normal'><center>". $closedTime." </center></td></tr>";
}
}
I got this info by looking at @gabriele's answer where he posted about array_slice
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments