Steve R.
Retired
- Local time
- Today, 10:10
- Joined
- Jul 5, 2006
- Messages
- 4,684
The intent of the two queries below is to retrieve the most recent magazine issue number ($maxissuenum). The code below works. The question is if there is a more efficient approach.
The first query returns the most recent date. The second query returns the maxium primary key (the issue number) for that speciic date. The maxium primary key in itself does NOT indicate the most recent issue, since the magazine data can be entered out-of-sequence.
The first query returns the most recent date. The second query returns the maxium primary key (the issue number) for that speciic date. The maxium primary key in itself does NOT indicate the most recent issue, since the magazine data can be entered out-of-sequence.
Code:
// ------------------------------------------------------------------------------
// Get Most Recent Issue Date.
$query = "SELECT MAX(IssueDate) FROM tblIssueList";
$result =$conn->query($query);
if (!$result) die($conn->error);
// Note use of "MYSQL_ASSOC" and "MYSQLI_NUM"
$row=mysqli_fetch_array($result, MYSQLI_NUM);
$maxdate=$row[0];
// ------------------------------------------------------------------------------
// Get Max Issue Number for most Recent Date
$query = "SELECT MAX(IssueIDNUM) FROM tblIssueList WHERE IssueDate = '$maxdate'";
$result =$conn->query($query);
if (!$result) die($conn->error);
// Note use of "MYSQL_ASSOC" and "MYSQLI_NUM";
$row=mysqli_fetch_array($result, MYSQLI_NUM);
$maxissuenum=$row[0];