Re: Alternating Links
| From: | conbud | Date: | Fri, 20 Dec 2002 06:32:12 +0000 |
| Subject: | Re: Alternating Links | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-128953@lists.php.net to get a copy of this message | ||
Hey, thanks. I should have thought about it longer, since I made something the exact same to alternate <tr> bgcolors. Thanks for refreshing though.
Justin French wrote:
There was a post on a similar thing the other day, and about once a week for the past few years :P Quick (untested) example: <table> <? $i = 0; $sql = 'select link from tablename'; $result = mysql_query($sql); while($myrow = mysql_fetch_array($result)){ $i++; if($i == 1) { echo '<tr>'; } echo "<td>{$myrow['link']}</td>"; if($i == 2) { echo '</tr>'; $i = 0; } }?> </table> This is easily adaptable to three (or more) columns by changing the last if() statement... Justinon 20/12/02 5:21 PM, conbud (conbudd@yahoo.com) wrote:Hi. Lets says I have 8 links stored in a database, extracting those links is no problem. Now lets says I have 2 columns, how do I get link 1 into column 1 then get link 2 into column 2 then link 3 into column 1 and link 4 into column 2 and so on... <table> <tr> <td>This is column 1</td> <td>This is column 2</td> </tr> </table> -- Conbud Graphic & Web Design Using Open Source Technology --