matthew9090 Posted April 3, 2011 Share Posted April 3, 2011 i'm back again and i am not very good with tables as the <tr> and <td> tags confuse me i need to put 2 sets of links into 2 columns in the table and they come out jumbled up. <table> <tr> <th>column 1</th> <th>column 2</th> </tr> <?php $sites = array_map('trim',file('websites.txt')); //read the whole file into an array & trim the newline character from the end of each line foreach ($sites as $link) { echo "<tr><td><a href='$link'>$link</a></td>"; } $sites = array_map('trim',file('websites2.txt')); //read the whole file into an array & trim the newline character from the end of each line foreach ($sites as $link) { echo "<td><a href='$link'>$link</a></td></tr>"; } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/232566-putting-links-into-table/ Share on other sites More sharing options...
dcro2 Posted April 3, 2011 Share Posted April 3, 2011 How do you expect it come out exactly? The way you have it set up right now you'll just have a ton of columns with one link inside each. <tr> is a row. <td> is a column. Each <tr> (row) of a table can have multiple <td> (column) inside, and of course you have to end the <tr> in order to get a new row. Quote Link to comment https://forums.phpfreaks.com/topic/232566-putting-links-into-table/#findComment-1196265 Share on other sites More sharing options...
matthew9090 Posted April 4, 2011 Author Share Posted April 4, 2011 it needs to look like this: Header Header website list 1 website list 2 website list 1 website list 2 and i've got this code: <?php $file1 = array_map('trim',file('websites.txt')); foreach ($file1 as $link) { echo "<a href='$link'>$link</a>"; } ?> <?php $file2 = array_map('trim',file('websites2.txt')); foreach ($file2 as $link2) { echo "<a href='$link2'>$link2</a>"; } ?> but i don't know how to put it into a table that looks like above. Quote Link to comment https://forums.phpfreaks.com/topic/232566-putting-links-into-table/#findComment-1196487 Share on other sites More sharing options...
dcro2 Posted April 4, 2011 Share Posted April 4, 2011 <table> <tr> <th>column 1</th> <th>column 2</th> </tr> <?php $file1 = array_map('trim',file('websites.txt')); $file2 = array_map('trim',file('websites2.txt')); for($i=0; $i<count($file1); $i++) { echo "<tr>\n"; echo " <td><a href='$file1[$i]'>$file1[$i]</a></td>\n"; echo " <td><a href='$file2[$i]'>$file2[$i]</a></td>\n"; echo "</tr>\n"; } ?> </table> Just make sure both files have the same number of links (or turn off warnings with error_reporting()). Quote Link to comment https://forums.phpfreaks.com/topic/232566-putting-links-into-table/#findComment-1196659 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.