Hiya,
I have written a mySQL query in PHP and it's displaying records, but only every other record. It's actually two queries - one gets initial data, and then using that it goes and fetches related data in another table.
Aim:
- to display 5 records from 'nsession' table
- the records should be ordered in descending order based on the 'info' field (a unix timestamp)
table 'nsession' acts as a log file for all logins and table 'nmembers' is a table containing the members profiles - the aim is to display the last 5 logins...
Here is the code I am currently using:
<script language="PHP">
include("database.php");
$result = mysql_query ("SELECT * FROM nsession
WHERE stat='1'
ORDER BY info DESC
LIMIT 0,10
");
if ($row = mysql_fetch_array($result)) {
do {
$logtime = strftime("%R",$row[2]);
$resultp = mysql_query ("SELECT * FROM nmembers
WHERE userid = '$row[1]'
");
if ($rowp = mysql_fetch_array($result)) {
do {
$lastinit = substr($rowp[2], 0, 1);
$firstname = substr($rowp[1], 0, 13);
} while($rowp = mysql_fetch_array($resultp));
} else {
}
echo $logtime." <a href=\"profile.php?".$row[0]."\">".$firstname." ".$lastinit."</a><br>";
} while($row = mysql_fetch_array($result));
} else {
}
</script>
Thanks,
Philip :-)