If you only want to use "name" from the db then only select "name", otherwise you are just wasting system resources.
<?
mysql_connect($host, $user, $pass);
mysql_select_db($db_name);
// if you only want to display "name" - only select "name", NOT "*"
$sql = "SELECT name FROM swd_user WHERE fk_account = 2 ORDER BY pk_user DESC LIMIT 10";
$res = mysql_query($sql) or die('Query failed.<br>Error: ' . mysql_error());
//change this to assoc
while ($row = mysql_fetch_row($res)) {
// store rows in an array
$desc[] = $row;
}
// reverse the array
$reversed = array_reverse($desc);
$num_rows = count ($reversed);
echo '<table border=1>';
// loop through rows
for ($i=0 ; $i<$num_rows ; $i++) {
$row = $reversed[$i];
if($i % 2)
$color = 'white';
else
$color = 'lightblue';
$num_fields = count ($row);
echo '<tr bgcolor="' . $color . '">';
// loop through fields
for ($j=0 ; $j<$num_fields ; $j++) {
echo "<td>$row[$j]</td>";
}
echo '</tr>';
}
echo '</table>';
?>
You could get rid of the field loop and change the mysql_fetch_row() to mysql_fetch_assoc() -
<?
mysql_connect($host, $user, $pass);
mysql_select_db($db_name);
// if you only want to display "name" - only select "name", NOT "*"
$sql = "SELECT name FROM swd_user WHERE fk_account = 2 ORDER BY pk_user DESC LIMIT 10";
$res = mysql_query($sql) or die('Query failed.<br>Error: ' . mysql_error());
//change this to assoc
while ($row = mysql_fetch_assoc($res)) {
// store rows in an array
$desc[] = $row;
}
// reverse the array
$reversed = array_reverse($desc);
$num_rows = count ($reversed);
echo '<table border=1>';
// loop through rows
for ($i=0 ; $i<$num_rows ; $i++) {
$row = $reversed[$i];
if($i % 2)
$color = 'white';
else
$color = 'lightblue';
echo '<tr bgcolor="' . $color . '">';
echo "<td>$row['name']</td>";
echo '</tr>';
}
echo '</table>';
?>
Hope this helps 😉