Solved

incrementing or counting after each loop

Posted on 2001-06-07
2
208 Views
Last Modified: 2006-11-17


Hi,

I have script below that gets a file, makes an array, then puts parts of the array into an html table.

I am trying to make it so that the table has two columns.  I am not sure how to write it so that $num increments after each foreach statement.  I think I have the rest of it right, just have to work out how to count and recount after each loop so the <TR> and </TR> print out in the right places.

Thank you,

Chris


<TABLE WIDTH="90%" BORDER="0" CELLPADDING="3">
<?
$newsarray = file ("/home/acc/example.com/newsfeed/$filename.txt");
$num = count ($newsarray);

foreach ($newsarray as $hdln) {
$news = explode ("\t",$hdln);
$url =  ($news[0]);
$title = ($news[1]);
$source = ($news[2]);
$date = ($news[7]);

if($num%2 == 0) {
PRINT "<TR>\n";
}

PRINT "<TD><B><FONT SIZE=\"-1\"><A HREF=\"javascript:story('$url')\"
ONMOUSEOVER=\"self.status='news'; return true;\"
ONMOUSEOUT=\"self.status='';\">$title</A></FONT></B><BR>
<FONT COLOR=\"#934900\" SIZE=\"-1\">$source&nbsp;&nbsp;&nbsp;$date</FONT></TD>";

if($num%2 == 0) {
PRINT "</TR>\n";
}
}
?>
</TABLE>
0
Comment
Question by:ChrisAndrews
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
ykf2000 earned 75 total points
ID: 6166795
try this:


<TABLE WIDTH="90%" BORDER="0" CELLPADDING="3">
<?
$newsarray = file ("/home/acc/example.com/newsfeed/$filename.txt");
$num = 0;

foreach ($newsarray as $hdln) {
$news = explode ("\t",$hdln);
$url =  ($news[0]);
$title = ($news[1]);
$source = ($news[2]);
$date = ($news[7]);

if($num%2 == 0) {
PRINT "<TR>\n";
}

PRINT "<TD><B><FONT SIZE=\"-1\"><A HREF=\"javascript:story('$url')\"
ONMOUSEOVER=\"self.status='news'; return true;\"
ONMOUSEOUT=\"self.status='';\">$title</A></FONT></B><BR>
<FONT COLOR=\"#934900\" SIZE=\"-1\">$source&nbsp;&nbsp;&nbsp;$date</FONT></TD>";
$num = $num + 1;

if($num%2 == 0) {
PRINT "</TR>\n";
}


}
?>
</TABLE>
0
 

Author Comment

by:ChrisAndrews
ID: 6167842

Works :)

Thank you,

Chris
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question