I'm trying to create my own result paging system, the power of which is held in the following for loop as it looks so far:
for ($i = 0; $i <= $resultsperpage; $i++)
{
$row = ($currentpage * $resultsperpage) - 1;
$row = $row + $i;
$userid = mysql_result($result, $row, "userid");
$username = mysql_result($result, $row, "username");
$location = mysql_result($result, $row, "location");
printf("<tr><td><a href=\"profile.php?userid=%s\">%s</a></td></tr>", $userid, $username);
printf("<tr><td>%s</td></tr>", $location);
}
There's likely a mistake up there somewhere, but I'm new to PHP, so if there is, I haven't picked up on it. But whether it contains minor errors or not is not the concern at the moment.
The script is to make a list of all the members in the database, and will therefore require at least another 5 fields each on top of userid, username and location. The above 3 merely serve as an example of what I want to do. The user details are to be displayed in a table, spread across multiple pages.
The variables of currentpage and resultsperpage are set further up the page, and the loop finds out what row of the database it is to query by multiplying the $currentpage number with the $resultsperpage. It then adds on the current value of the for variable $i, and finally takes one away, since the mysql result thing starts at 0 instead of 1.
While I believe with fine tuning and more added to it, this would work, it seems awfully inefficient. mysql_result would be much better replaced by mysql_fetch_array, or something like that, that got all of the information at once. However, mysql_result is the only way I have found that accepts a numeric value to indicate which row exactly you want to get the information from. Surely running one command to find the value of all the rows instead of seperate calls is much more efficient, but is there a way that one command can be done while still specifying which row from the query results you want to take the information from?
As I said earlier, I could likely be missing something that seems obvious, but thanks for any help _