im wondering if there is a way to display the data of sql table row by row until it either reaches the last data element or reaches a predefined number, say 10.
i can, and have working a script that will display the data row by row untill it reaches the end of the data. I also can get it to count to 10 with out a problem. the issue is the script will always count to 10, so if there isnt enough data in the table it spits out empty lines.
here is my code that spits out empty lines:
-Dave
i can, and have working a script that will display the data row by row untill it reaches the end of the data. I also can get it to count to 10 with out a problem. the issue is the script will always count to 10, so if there isnt enough data in the table it spits out empty lines.
here is my code that spits out empty lines:
Code:
<?php
include 'dbinfo.php';
include 'dbconnect.php';
$query="SELECT * FROM batting_rbi ORDER BY stat DESC";
$result=mysql_query($query);
//$num=mysql_numrows($result);
$num=10;
mysql_close();
?>
<table width="90%" border="1" cellspacing="1" cellpadding="1" bordercolor="#000000" bgcolor="#F8D8B8">
<tr>
<td class="tabletext"><h4>#</h4></td>
<td class="tabletext"><h4>Player</h4></td>
<td class="tabletext"><h4>Year</h4></td>
<td class="tabletext"><h4>Team</h4></td>
<td class="tabletext"><h4>Average</h4></td>
</tr>
<?php
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"name");
$year=mysql_result($result,$i,"year");
$team=mysql_result($result,$i,"team");
$stat=mysql_result($result,$i,"stat");
$id=mysql_result($result,$i,"id");
?>
<tr>
<td class="tabletext"><? echo $i+1 ?></td>
<td class="tabletext"><? echo $name ?></td>
<td class="tabletext"><? echo $year ?></td>
<td class="tabletext"><img src="images/logos/<? echo $team ?>.bmp" alt="<? echo $team ?> Logo"></td>
<td class="tabletext"><? echo $stat ?></td>
</tr>
<?
$i++;
}
echo "</table>";
?>
-Dave