PHP - 每行打印 4 个表(总共 12 个表),跳过表 5 和 10,这是不应该的
$rowcount=0;
$prodcount=0;
while (($record = fgetcsv($handle, 1000, "|")) !== FALSE) {
//here, the csv file is opened
$numrecords = count($record);
$produs=$record[1]; //records read
$pret=$record[3];
$imagine=$record[4];
if ($rowcount < $linecount) {
//linecount is the number of lines in my csv file and i take 1 from it. for some reason it shows one extra entry when i use count()
if($rowcount > 0) //this line skips the first csv line (table head)
{
if ($rowcount %5 != 0) {
//this line is where my problem lies. i think it's because of the modulus operator
if ($prod_count==5) {$prod_count="1";}
if ($prod_count==1) {print ("<tr>");} //these two lines limit the drawn tables to 4 per row
print "some table";
}else {
//this line is where I think i can fix it. Just need to decrement $rowcount by one. $rowcount -= 1; thing is: it doesn't work for some reason when i take 1 from $rowcount, the whole script freezes and only displays 4 table out of 12, which is the number of rows minus the first one in my csv file.
$table_lastrow=0;
if ($rowcount <= $linecount){
print ("</tr><tr><td height='30'></td></tr>");
}
}
}}
$rowcount++;
$prod_count++;
}
$rowcount=0;
$prodcount=0;
while (($record = fgetcsv($handle, 1000, "|")) !== FALSE) {
//here, the csv file is opened
$numrecords = count($record);
$produs=$record[1]; //records read
$pret=$record[3];
$imagine=$record[4];
if ($rowcount < $linecount) {
//linecount is the number of lines in my csv file and i take 1 from it. for some reason it shows one extra entry when i use count()
if($rowcount > 0) //this line skips the first csv line (table head)
{
if ($rowcount %5 != 0) {
//this line is where my problem lies. i think it's because of the modulus operator
if ($prod_count==5) {$prod_count="1";}
if ($prod_count==1) {print ("<tr>");} //these two lines limit the drawn tables to 4 per row
print "some table";
}else {
//this line is where I think i can fix it. Just need to decrement $rowcount by one. $rowcount -= 1; thing is: it doesn't work for some reason when i take 1 from $rowcount, the whole script freezes and only displays 4 table out of 12, which is the number of rows minus the first one in my csv file.
$table_lastrow=0;
if ($rowcount <= $linecount){
print ("</tr><tr><td height='30'></td></tr>");
}
}
}}
$rowcount++;
$prod_count++;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我理解你想要什么,那么你已经让事情变得更加复杂了,因为有许多不需要的额外变量。
看看下面的代码是否产生了您所期望的结果(请注意,这会产生一个没有数据的表,这正是您的代码产生的结果,因为您从不使用
$produs
,$pret< /code> 或
$imagine
任何地方):If I understand what you want right, you have made this a lot more complicated with many extra variables that are not required for this.
See if the following code produces what you are expecting (note that this produces a table with no data in it, which is what your code produces, because you never use
$produs
,$pret
or$imagine
anywhere):也许这更适合你想要的东西..阅读行并将第一行放在第一列中,第二行放在第二列中,第三行放在第三列中,4.放在4. - 5.中被跳过,6.再次放在第一栏....
Maybe this fits more the thing you want .. read in the lines and put the first line in the first column, second in the second, third in the third and 4. in the 4. - 5. is skipped and 6. again in the first column ....