我正在使用Bittrex的API,读取json,然后使用for循环遍历以获取我需要的信息
一切正常。这是代码:
foreach($return[result] as $x=>$x_value){
extract($x_value);
echo $OrderUuid." " .$closedDate ." " .$closedTime ." " .$Quantity." " .$Price." " . $PricePerUnit * 100000000 ." <br>";
}
但是,我想要做的是因为我把它放到一个分页的表格中我需要能够只回显1-5结果,然后下一页将是6-11等等
我已经通过使用它知道了计数,它返回结果的数量。
$thisManyResults=count($return[result]);
我知道我需要记住,索引也是从ZERO开始的。
循环让我非常困惑,请为新手解释一下他的头脑。谢谢
编辑:
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>";
}
但是这显示所有结果0-22(23个结果)我需要能够只在表0到5或6到10中显示
答案 0 :(得分:1)
我希望这可以帮助你
StepL
答案 1 :(得分:0)
这是最终代码,以防其他人得到帮助
$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>";
}
}
我通过查看@gabriele的答案得到了这个信息,他发布了array_slice