Solved

incrementing or counting after each loop

Posted on 2001-06-07
2
184 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
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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 is …
The viewer will learn how to dynamically set the form action using jQuery.
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now