[thelist] PHP to insert press Releases into a detail page

Kasimir K evolt at kasimir-k.fi
Sat Sep 24 03:04:57 CDT 2005


jono at charlestonwebsolutions.com scribeva in 2005-09-23 20:15:
> Seems pretty easy...or atleast I can follow what is going on enough to be
> able to figure it out.  One thing I am not sure about:
> 
> Does the following create a list of links that users click on:?
> 
>><?php
>>require "pr_articles.php";
>>?>
>>...
>><?php
>>for ($i = 0; $i < count($articles); $i++){
>>    echo "<a href='pr_detail.php?article=" . $i . "'>"
>>       . $articles[$i]['title'] . "</a><br>";
>>}
>>?>
> 
> 
> I believe it does - I see the echo "<a href=...> - but I just wanted to
> make sure that was the case.

It indeed does. The 'for' loops through all articles, and 'echo' outputs 
a link for each to the browser. For simplicity I used a <br> to split 
the links to lines, but a neater option would be to use <li>, and it's 
easy to include styles as well:

<ul>
<?php
for ($i = 0; $i < count($articles); $i++){
     echo "<li class='artList'><a href='pr_detail.php?article="
       . $i . "'>" . $articles[$i]['title'] . "</a></li>";
}
?>
</ul>

Note also the use on single quotes for class and href attributes - this 
is because we use double quotes to delimit the string we output with echo.

.k


More information about the thelist mailing list