Hi All,
WHen I used this script I encounted a couple of problems, and wondered if you could help...
The first of which was that the script seems to miss out the 0's record, so it starts with the second line of the db... So I just changed it slightly to this:
<?
require( "common/common.php" );
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM TableName ORDER BY `Surname` ASC "; // Fetch rows from content table and display ALL pages
$result = mysql_query($query);
$num_records = mysql_num_rows($result); //Total number of records in result
$num_per_row = 3; //Change to however many columns per row you desired
mysql_close();
echo "<table width=\"500\">";
$i = 1;
$j = 0;
while ($row = mysql_fetch_array($result)) {
$id=mysql_result($result,$j,"ID");
$firstname=mysql_result($result,$j,"Firstname");
$surname=mysql_result($result,$j,"Surname");
$bio=mysql_result($result,$j,"Bio");
if (($i == 1) || (($i > $num_per_row) && (($i % $num_per_row) == 1))) {
echo "<tr>";
}
echo "<td width=\"33%\"><div align=\"left\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><a href=\"test2.php?Name=$firstname $surname\">$surname, $firstname</a></font></div></td>";
if (($i == $num_records) || (($i >= $num_per_row) && (($i % $num_per_row) == 0))) {
//Fill in empty columns as necessary
if (($i == $num_records) && ($i % $num_per_row != 0)) {
$n = $num_per_row - ($i % $num_per_row);
echo '<td colspan="' . $n . '"> </td>';
}
echo "</tr>";
}
$i ++;
$j ++;//Increment counters
}
echo "</table>";
?>
I hope that this helps anyone else...
I was wondering however, if there was a quick and dirty way to have
<tr>
<td>1/3 of results</td>
<td> next 1/3 of results</td>
<td> last 1/3 of results</td>
</tr>
I thought about using $i = 1/3*$num_of_results - but I don't know the right syntax... any one any ideas if that's even possible?
Thanks in advance...
Robin