Get Current Row Number (Cursor Location) (1 Viewer)

Steve R.

Retired
Local time
Today, 02:24
Joined
Jul 5, 2006
Messages
1,846
mysqli_data_seek works to get to a specific record. The problem that I am having is finding a method that returns the current cursor location.

I am developing PHP code to allow scrolling to either the next record or to the prior record. One way to accomplish this would be to have a query which keys the row number to the primary key (IssueIDNUM).

Would that be the way to go, or are there other alternative approaches?

Code:
$query = "Select (@row_number:=@row_number + 1) AS rownumber, IssueIDNUM FROM tblIssueList, (SELECT @row_number:=0 ) AS tblTemp ORDER by IssueDate DESC, IssueIDNUM";
 

Steve R.

Retired
Local time
Today, 02:24
Joined
Jul 5, 2006
Messages
1,846
Since posting, I have been experimenting with how to get the current row number. The SQL query in the original post is unnecessary. The "better" query is below.

Code:
$query = "Select IssueIDNUM FROM tblIssueList ORDER by IssueDate DESC, IssueIDNUM ";
A "beta" version of how to get the current row (cursor position) is below. I think the code can be substantially shrunk as I learn more.

Code:
$current_row_number = return_row_number();
Code:
<?php

      function return_row_number() 
	{ 	
		// Loop through the Array; Get Row Number for the current issue
		global $result,$issuenum, $rowcount;
		$count =0;
		mysqli_data_seek($result, 0);
		while($row=mysqli_fetch_array($result, MYSQL_ASSOC))
   		{
      		++$count;
      		if($issuenum == $row['IssueIDNUM'])
      		{
					return $count -1;
					break;
      		}
         }	
	} 
?>
I also found on the W3 School website a listing of PHP 5 Array Functions. Yea, now I can get some DAO compatibility.:)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom