Smackie wrote:Alright i just started working on this script like 2 hours ago and well i came up in a bind. its suppose to show each flotilla and other fields from database and then in the second database is to report how many officers are in that flotilla the thing is it shows only 1 record and outputs whats suppose to be outputted but the thing is i need it to output more then just one record.
here is the script.
<table width="590" border="1">
<tr>
<td class="txt" colspan="6"><center>SSVN Flotilla's</center></td>
</tr>
<tr>
<td class="txt">Flotilla</td>
<td class="txt">Location</td>
<td class="txt">Insignia</td>
<td class="txt">Flotilla Commander</td>
<td class="txt">Flotilla Vice Commander</td>
<td class="txt">Officers</td>
</tr>
<?php
$sql = "SELECT * FROM flotilla";
$result = mysql_query($sql);
while ($rows = mysql_fetch_array($result)) {
$flotilla = $rows['flotilla'];
$location = $rows['location'];
$insignia = $rows['insignia'];
$commander = $rows['commander'];
$vcommander = $rows['vcommander'];
$sql = "SELECT COUNT(flotilla) FROM users WHERE flotilla = '$flotilla' ORDER BY flotilla";
$result = mysql_query($sql);
//Print out result
while($row = mysql_fetch_array($result)){
?>
<tr>
<td class="txt"><?php echo $flotilla; ?> </td>
<td class="txt"><?php echo $location; ?> </td>
<td class="txt"><img src="<?php echo $insignia; ?>"></td>
<td class="txt"><?php echo $commander; ?> </td>
<td class="txt"><?php echo $vcommander; ?> </td>
<td class="txt"><?php echo number_format($row['COUNT(flotilla)']); ?> </td>
</tr>
<?php
} }
?>
</table>
Hi, the problem is in your first while loop. each time the loop repeats it over writes the values of $flotilla, $location, etc. Also, your doing your row count wrong
Try:
while ($rows = mysql_fetch_array($result)) {
$flotilla[] = $rows['flotilla'];
$location[] = $rows['location'];
$insignia[] = $rows['insignia'];
$commander[] = $rows['commander'];
$vcommander[] = $rows['vcommander'];
$result_2 = mysql_query("SELECT flotilla FROM users WHERE flotilla = '".$rows['flotilla']."'");
$flotilla_count[] = mysql_num_rows($result_2);
}
This will turn them all into arrays. Then then change the second while to
for($i=0; $i < count($flotilla); $i++)
{
?>
<tr>
<td class="txt"><?php echo $flotilla[$i]; ?> </td>
<td class="txt"><?php echo $location[$i]; ?> </td>
<td class="txt"><img src="<?php echo $insignia[$i]; ?>"></td>
....
....
<td class="txt"><?=number_format($flotilla_count[$i])?> </td>
<?php
}
I'm not sure exaclty what your doing with your row count because there are ways that your select can return a set of results that can be used with mysql_fetch_array, but because of the way that your trying to use the results I'm assuming that your hoping for the actual count of the rows.
Sorry if this doesn't help