Hi all,
i want to split the results that i want to display in 5 rows per page. The script displays the first 5 results but then i have following warning:
Warning: mysql_result(): Unable to jump to row 5 on MySQL result index 6 in C:\www\paging1.php on line 53...
If somebody knows what might be the mistake please answer me as soon as posible..Thank you
<?php
function paging1() {
$key = $_POST['TEXTFIELD'];
if (!empty($key))
{
$limit=5; // rows to return
$numresults=mysql_query("select * from papernew where (title LIKE '%".$key."%') OR (authorName1 LIKE '%".$key."%') OR
(authorName2 LIKE '%".$key."%') OR (authorName3 LIKE '%".$key."%') OR (authorName4 LIKE '%".$key."%')
OR (authorName5 LIKE '%".$key."%') OR (authorLastName1 LIKE '%".$key."%') OR (authorLastName2 LIKE '%".$key."%')
OR (authorLastName3 LIKE '%".$key."%') OR (authorLastName4 LIKE '%".$key."%') OR (authorLastName5 LIKE '%".$key."%')
OR (publisher LIKE '%".$key."%') OR (publisherDate LIKE '%".$key."%')OR (type LIKE '%".$key."%')
OR (keywords11 LIKE '%".$key."%') OR (keywords12 LIKE '%".$key."%')OR (keywords13 LIKE '%".$key."%')
OR (keywords14 LIKE '%".$key."%') OR (keywords15 LIKE '%".$key."%') OR (keywords21 LIKE '%".$key."%')
OR (keywords22 LIKE '%".$key."%') OR (keywords23 LIKE '%".$key."%') OR (keywords24 LIKE '%".$key."%')
OR (keywords25 LIKE '%".$key."%') order by paperID desc");
$numrows=mysql_num_rows($numresults);
echo "numrows is: $numrows";
if (empty($offset)) {
$offset=1;
}
$result=mysql_query("select * from papernew where (title LIKE '%".$key."%') OR (authorName1 LIKE '%".$key."%')
OR (authorName2 LIKE '%".$key."%') OR (authorName3 LIKE '%".$key."%') OR (authorName4 LIKE '%".$key."%')
OR (authorName5 LIKE '%".$key."%') OR (authorLastName1 LIKE '%".$key."%') OR (authorLastName2 LIKE '%".$key."%')
OR (authorLastName3 LIKE '%".$key."%') OR (authorLastName4 LIKE '%".$key."%') OR (authorLastName5 LIKE '%".$key."%')
OR (publisher LIKE '%".$key."%') OR (publisherDate LIKE '%".$key."%')OR (type LIKE '%".$key."%')
OR (keywords11 LIKE '%".$key."%') OR
(keywords12 LIKE '%".$key."%')OR (keywords13 LIKE '%".$key."%') OR (keywords14 LIKE '%".$key."%') OR
(keywords15 LIKE '%".$key."%') OR (keywords21 LIKE '%".$key."%') OR (keywords22 LIKE '%".$key."%') OR
(keywords23 LIKE '%".$key."%') OR (keywords24 LIKE '%".$key."%') OR (keywords25 LIKE '%".$key."%')
order by paperID desc" . " LIMIT $offset,$limit");
$i = 0;
if ($numrows == 0)
{
echo "no result returned";
}
while ($i < $numrows)
{
$path = mysql_result($result, $i, "path");
$authorName1 = substr(mysql_result($result,$i,"authorName1"), 0, 1).".";
$authorLastName1 = mysql_result($result,$i,"authorLastName1");
$fname = $authorName1." ".$authorLastName1.",";
echo "<i>".$fname."</i>";
for ($j = 2;$j < 6; $j++)
{
if (is_null(mysql_result($result,$i,"authorName".$j)))
{ $fname[$j] = "";
$fname = $fname.", ".$fname[$j];
}else
{
$authorName[$j] = mysql_result($result,$i,"authorName".$j);
$authorLastName[$j] = mysql_result($result,$i,"authorLastName".$j);
if (!empty($authorLastName[$j]))
{
$authorName[$j] = substr(mysql_result($result,$i,"authorName".$j), 0, 1).".";
$authorLastName[$j] = mysql_result($result,$i,"authorLastName".$j);
$name = $authorName[$j]." ".$authorLastName[$j].", ";
echo "<i>".$name."</i>";
}
}//end of else
}//end of for
$title = mysql_result($result,$i,"title");
$publisher = mysql_result($result,$i,"publisher");
$publisherDate = mysql_result($result,$i,"publisherDate");
$pagesfrom = mysql_result($result,$i,"pagesfrom");
$pagesto = mysql_result($result,$i,"pagesto");
$paperid = mysql_result($result, $i, "paperID");
$i++;
echo "<br><b><i>".$title."<br></b></i>"."<i>".$publisher."</i>, "
.$publisherDate.", pp. " .$pagesfrom."-".$pagesto.".";
echo "<p align=\"left\"><a href=\"$path\">Download</a>"."  ";
echo "<a href=\"bibtex.php?paperid=".$paperid."\">View Bibtex</a>"."  ";
echo "<br><br>";
}
// next we need to do the links to other results
if ($offset==1) { // bypass PREV link if offset is 0
$prevoffset=$offset-20;
print "<a href=\"$PHP_SELF?offset=$prevoffset\">PREV</a> \n";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$limit*($i-1);
print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> \n";
}
// check to see if last page
if (!(($offset/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$newoffset=$offset+$limit;
print "<a href=\"$PHP_SELF?offset=$newoffset\">NEXT</a><p>\n";
}
}
}
?>