[thelist] php/mysql get next two records
Ken Schaefer
Ken at adOpenStatic.com
Mon Feb 7 03:53:50 CST 2005
Can you use TOP in mySQL?
SELECT
TOP 3 <whatever fields>
FROM
myTable
WHERE
myField => myCriteria
ORDER BY
myField
(myCriteria would be whatever you'd using to get you the current record, and
TOP 3 would be the current record, and the next two records after that
according to the sort order in the ORDER BY clause)
Cheers
Ken
: -----Original Message-----
: From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On
: Behalf Of Mark Groen
: Sent: Monday, 7 February 2005 12:19 PM
: To: thelist at lists.evolt.org
: Subject: [thelist] php/mysql get next two records
:
: this is probably really simple but... could some enlighten me to
: getting the next two records (next, after that) following the first
: one (now playing) to be displayed?
:
: $myHour = date("H");
: $myDay = date("l");
: $nowPlaying = 0;
:
: $query = "SELECT id,title,dj,show_day,show_start,show_end FROM
: schedule ";
: $query .= "WHERE time_format(show_start,'%H') = '$myHour'";
: $mysql_result = mysql_query($query, $mysql_link);
:
: if($row = mysql_fetch_row($mysql_result))
: { $id = $row[0];
: $title = $row[1];
: $dj = $row[2];
: $show_day = $row[3];
: $show_start = $row[4];
: $show_end = $row[5];
:
: print("<h1>now playing</h1>");
:
: if($show_day == $myDay)
: {
: print("<strong>");
: $str = ("2005-02-07" . " $show_start");
: if (($timestamp = strtotime($str)) === -1) {
: echo "nothing on right now";
: } else {
: echo date('g:i', $timestamp);
: }
: print(" - ");
: $str2 = ("2005-02-07" . " $show_end");
: if (($timestamp = strtotime($str2)) === -1) {
: echo "nothing on right now";
: } else {
: echo date('g:i', $timestamp);
: }
: print("</strong<br>$title");
: }
:
: $nowPlaying++;
: if($nowPlaying == 1)
: {print("<h1>next</h1>");
: print("<strong>$show_start - $show_end ::</strong><br>");
: print("$title");
: }
: // and then one more listing,
: //format now playing, next as below
: //after that
: //2:00 - 2:10 ::
: //Legal Alert
: }
:
: txs, slighty addled,
:
: Mark
More information about the thelist
mailing list