I'm wondering if anyone can help me out - i'm in the middle of making a new script, it grabs data from a table, and sorts the data alphabetically. The data will be placed in a table, but at the moment it does each result on a new line, i need it so it makes two columns for the first two results then moves down and makes another two etc.. hope i explained enough.. thanks
try this... print "<table>"; while still got items to process { print "<tr>"; while less than 2 times { print "<td>"; if(still got items to process) { print item } else { leave empty } print "</td>"; } print "</tr>"; } print "</table>"; Code (markup):
Daboss - thanks i will try it afterwards, but i've came across another issue which i dont know how to fix. I havent done php in a year and i wish i kept with it But i have; $sql = "select * from breeds order by name"; $result = mysql_query($sql, $conn) or die(mysql_error()); while ($list = mysql_fetch_array($result)) { $letter = strtoupper(substr($list['name'],0,1)); if ($letter != $prev_row) { echo "<br><table width=\"100%\" class=\"contenttable\" cellpadding=\"0\" cellspacing=\"0\"> <tr> <td width=\"22\" height=\"22\" class=\"contentbox\"> '"; echo($letter); echo ("' Dog Breeds</td> </tr> <tr> <td class=\"in\"><p>"); } $name = $list['name']; foreach($breed as $name => $letter){ echo "<a href=\"info/$name/\">$name</a> -"; } if($letter != $prev_row){ echo("</p></td> </tr> </table> "); } $prev_row = $letter; } Code (markup): that should print out each field which is under A, B, C, D etc, but i find that it echo's the first field then the second goes into an empty space out of the table, then the first B item works etc. Sorry but has anyone got any ideas Sorry if im been a pain in the ass I tried adding foreach() rather than echo for the fields but it doesnt seem to work. I just need it to echo all A's in the A table
Right i've taken a look on PHPfreaks.com and changed the code that i posted before to this; <?php include('conn.php'); $sql = 'SELECT * FROM breeds ORDER BY name'; $result = mysql_query($sql) or die('ERROR: '.$query.' '.mysql_error()); $letterlinks = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; echo '<a name="top"></a>'; echo '<a href="#number">0-9</a> '; for ($i = 0; $i < 37; $i++): echo '<a href="#'.$letterlinks[$i].'">'.$letterlinks[$i].'</a> '; endfor; while ($list = mysql_fetch_object($result)): $letter = strtoupper(substr($list->name, 0, 1)); if ($prev_row != '0-9' && is_numeric($letter)): echo '<br /><a name="number"></a><b><u>0-9</u></b> '; echo '<a href="top"><i>goto top</i></a><br />'; $prev_row = '0-9'; endif; if ($letter != $prev_row && !is_numeric($letter)): echo '<br /><a name="'.$letter.'"></a><b><u>'.$letter.'</u></b> '; echo '<a href="top"><i>goto top</i></a><br />'; $prev_row = $letter; endif; echo $list->name.'<br />'; endwhile; ?> Code (markup): to display the results in order, it works but i want to add a table around each letter but i cant figure it out I need to be able to put a line of code before and after each letter is displayed... any ideas..
I only have it on localhost right now but it looks something like A - to top Abba Abby B - to top Bob Billy etc etc But i need to be able to put code after the end of each letter so something at the end of A and B etc