Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Avoiding the first decoration of an array 2

Status
Not open for further replies.

kupe

Technical User
Sep 23, 2002
376
0
0
A selection brings some text onto the webpage. I want to divide each of these entries of text with an <hr>.

And this does it -

while ($row = mysql_fetch_array($result)) {
echo '<p> <hr align="center" width="66%" color="#FAEBD7" size="1"></p>' . $row['Posted'] . '</p>';

Problem is I don't want that <hr> above the first item.
Is there a way to say, 'Not for the first item, please', please, Experts?
 
I often use something like:

$first_line = TRUE;
while ($row = mysql_fetch_array($result))
{
echo '<p>';
if (!$first_line)
{
echo '<hr align="center" width="66%" color="#FAEBD7" size="1">';
}
echo '</p>' . $row['Posted'] . '</p>';
$first_line = FALSE;
}


BTW, your <p></p> tags don't balance.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks very much, sleipnir214. It looks really good. Thanks for pointing out the </p> discrepancy. I've only been staring at it for hours over the weekend(!) Despair.
 
This is another way to do what you want, without the use of a "$first_line" indicator:
Code:
$tmp = array();
while ($row = mysql_fetch_array($result))
    $tmp[] = $row['Posted'];

echo '<p>';
echo implode('<hr align="center" width="66%" color="#FAEBD7" size="1">'."\n",$tmp);
echo '</p>';

Ken
 
New territory for me here, ken. Implode. That's going to take some dwelling on. Very grateful. Cheers
 
A small explanation:

The implode() fuction inserts a delimiter between elements of an array.

In this case I made your "<hr>" tag the delimiter. The "\n" at the end just makes the source (as viewed in a browser) more readable to people.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top