bschultz Posted May 11, 2010 Share Posted May 11, 2010 I need to figure out a way to count the number of items in an array (which is easy)...and then echo the results in an ordered fashion. I only want 8 results to show up per line. I'm sure it's some form of for loop, but I don't know where to start. This works...but it can't be the best way....plus what if I add more names to the array...??? <?php $count = count($umpires); if ($count <= echo "<a href = 'schedule_names.php?name=$umpires'>$umpires</a> "; elseif ($count >= 9) echo "<a href = 'schedule_names.php?name=$umpires[0]'>$umpires[0]</a> <a href = 'schedule_names.php?name=$umpires[1]'>$umpires[1]</a> <a href = 'schedule_names.php?name=$umpires[2]'>$umpires[2]</a> <a href = 'schedule_names.php?name=$umpires[3]'>$umpires[3]</a> <a href = 'schedule_names.php?name=$umpires[4]'>$umpires[4]</a> <a href = 'schedule_names.php?name=$umpires[5]'>$umpires[5]</a> <a href = 'schedule_names.php?name=$umpires[6]'>$umpires[6]</a> <a href = 'schedule_names.php?name=$umpires[7]'>$umpires[7]</a> <a href = 'schedule_names.php?name=$umpires[8]'>$umpires[8]</a> <br /><br /> <a href = 'schedule_names.php?name=$umpires[9]'>$umpires[9]</a> <a href = 'schedule_names.php?name=$umpires[10]'>$umpires[10]</a> <a href = 'schedule_names.php?name=$umpires[11]'>$umpires[11]</a> <a href = 'schedule_names.php?name=$umpires[12]'>$umpires[12]</a> <a href = 'schedule_names.php?name=$umpires[13]'>$umpires[13]</a> <a href = 'schedule_names.php?name=$umpires[14]'>$umpires[14]</a> <a href = 'schedule_names.php?name=$umpires[15]'>$umpires[15]</a> <a href = 'schedule_names.php?name=$umpires[16]'>$umpires[16]</a> <br /><br /> <a href = 'schedule_names.php?name=$umpires[17]'>$umpires[17]</a> <a href = 'schedule_names.php?name=$umpires[18]'>$umpires[18]</a> <a href = 'schedule_names.php?name=$umpires[19]'>$umpires[19]</a> "; ?> Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 11, 2010 Share Posted May 11, 2010 I believe that echo can be turned into... foreach($umpires as $data) { echo '<a href="schedule_names.php?name=' . $data . '">' . $data . '</a> $nbsp;$nbsp;$nbsp;$nbsp;$nbsp;$nbsp;$nbsp;$nbsp;$nbsp;$nbsp;'; } Quote Link to comment Share on other sites More sharing options...
bschultz Posted May 11, 2010 Author Share Posted May 11, 2010 Right...but that prints everybody in one line. I want no more than eight in each line. Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 11, 2010 Share Posted May 11, 2010 This would work for that. I didn't read your original question. $num = 1; foreach($umpires as $data) { echo '<a href="schedule_names.php?name=' . $data . '">' . $data . '</a> '; $num++; if($num == { echo '<br />'; $num = 1; } } Quote Link to comment Share on other sites More sharing options...
bschultz Posted May 11, 2010 Author Share Posted May 11, 2010 That did it...thanks! Quote Link to comment 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.