Nightfire
11-10-2002, 03:08 PM
I've got two scripts I'm wanting to marge, but I'm having problems figuring it out. I'm trying to add this code
$left = 1;
echo '<table cellpadding="2" cellspacing="2" border="0" align="center">';
while ($row = mysql_fetch_array ($result)){
if ($left){
echo '<tr><td><a href="javascript://" onclick="window.open(\'screenshot.php?image='.$row[image].'&sub='.$row[username].'\',null,\'height='.$row[height].',width='.$row[width].',status=no,toolbar=no,menubar=no,location=no,left=0,top=0\')"><img src="images/ss/'.$row[image].'" width="200" height="150" alt="Submitted by [CP]'.$row[username].'" border="0"></a><br><a href="javascript://" onclick="window.open(\'screenshot.php?image='.$row[image].'&sub='.$row[username].'\',null,\'height='.$row[height].',width='.$row[width].',status=no,toolbar=no,menubar=no,location=no,left=0,top=0\')">Submitted by [CP]'.$row[username].'</a></td>';
}else{
echo '<td><a href="javascript://" onclick="window.open(\'screenshot.php?image='.$row[image].'&sub='.$row[username].'\',null,\'height='.$row[height].',width='.$row[width].',status=no,toolbar=no,menubar=no,location=no,left=0,top=0\')"><img src="images/ss/'.$row[image].'" width="200" height="150" alt="Submitted by [CP]'.$row[username].'" border="0"></a><br><a href="javascript://" onclick="window.open(\'screenshot.php?image='.$row[image].'&sub='.$row[username].'\',null,\'height='.$row[height].',width='.$row[width].',status=no,toolbar=no,menubar=no,location=no,left=0,top=0\')">Submitted by [CP]'.$row[username].'</a></td></tr>';
}
$left = !$left;
}
if (!$left){
echo '<td> </td></tr>';
}
// odd number of $rows
echo '</table>';
into this code
$result= @mysql_query($sql);
$resultnum = @mysql_num_rows($result);
$DISPPAGE = 10; #DISPPAGE is the number of items displayed per page.
$NUMPAGES = ceil($resultnum / $DISPPAGE); #NUMPAGES to show how many pages you WILL get.
if($result): #Sanity check on query, only runs if valid query.
if($resultnum > 0): #We actually got some rows.
echo "<div align=\"right\">\n\n";
for($i = 1; $i <= $NUMPAGES; $i++): #loop to print << 1 2 3... $NUMPAGES >>
if($i == 1 && $PAGE > 1) #Prints the << first to goto the previous page (not on page 1)
echo "<a href=\"$PHP_SELF?page=".($PAGE - 1)."\" onMouseOver=\"status='Go to the Previous Page';return true;\" onMouseOut=\"status=' ';return true;\">« </a>";
if($i == $PAGE) #Doesn't print a link itself, just prints page number
echo " $i ";
if($i != $PAGE) #Other links that aren't this page go here
echo "<a href=\"$PHP_SELF?page=$i\" onMouseOver=\"status='Go to Page $i';return true;\" onMouseOut=\"status=' ';return true;\"> $i </a>";
if($i == $NUMPAGES && $PAGE != $NUMPAGES) # Link for next page >> (not on last page)
echo "<a href=\"$PHP_SELF?page=".($PAGE + 1)."\" onMouseOver=\"status='Go to the Next Page';return true;\" onMouseOut=\"status=' ';return true;\"> »</a>";
endfor;
echo "\n</div>\n";
echo "\n";
$START = ($PAGE - 1) * $DISPPAGE;
mysql_data_seek($result,$START); #Moves the pointer to right row
#This loop will go until you a) reach $DISPPAGE or b) there aren't anymore entries
for($i = 1; $i <= $DISPPAGE && $ARET = @mysql_fetch_array($result); $i++):
//
// SCRIPT RESULTS SHOWN HERE
//
endfor;
endif;
if($resultnum == 0) #if we get no rows
echo "<div align=\"center\">The database is empty</div>\n";
endif;
if(!$result): # Bogus Query, or mysqld isn't running...
echo "<div align=\"center\">\n";
echo "Either the database is down, or the query was invalid\n";
echo "\n</div>\n";
endif;
The error I get when I put the first script into the above script is
Warning: Offset -10 is invalid for MySQL result index 2 in includes/screenshots.php on line 39
mysql_data_seek($result,$START); #Moves the pointer to right row
$left = 1;
echo '<table cellpadding="2" cellspacing="2" border="0" align="center">';
while ($row = mysql_fetch_array ($result)){
if ($left){
echo '<tr><td><a href="javascript://" onclick="window.open(\'screenshot.php?image='.$row[image].'&sub='.$row[username].'\',null,\'height='.$row[height].',width='.$row[width].',status=no,toolbar=no,menubar=no,location=no,left=0,top=0\')"><img src="images/ss/'.$row[image].'" width="200" height="150" alt="Submitted by [CP]'.$row[username].'" border="0"></a><br><a href="javascript://" onclick="window.open(\'screenshot.php?image='.$row[image].'&sub='.$row[username].'\',null,\'height='.$row[height].',width='.$row[width].',status=no,toolbar=no,menubar=no,location=no,left=0,top=0\')">Submitted by [CP]'.$row[username].'</a></td>';
}else{
echo '<td><a href="javascript://" onclick="window.open(\'screenshot.php?image='.$row[image].'&sub='.$row[username].'\',null,\'height='.$row[height].',width='.$row[width].',status=no,toolbar=no,menubar=no,location=no,left=0,top=0\')"><img src="images/ss/'.$row[image].'" width="200" height="150" alt="Submitted by [CP]'.$row[username].'" border="0"></a><br><a href="javascript://" onclick="window.open(\'screenshot.php?image='.$row[image].'&sub='.$row[username].'\',null,\'height='.$row[height].',width='.$row[width].',status=no,toolbar=no,menubar=no,location=no,left=0,top=0\')">Submitted by [CP]'.$row[username].'</a></td></tr>';
}
$left = !$left;
}
if (!$left){
echo '<td> </td></tr>';
}
// odd number of $rows
echo '</table>';
into this code
$result= @mysql_query($sql);
$resultnum = @mysql_num_rows($result);
$DISPPAGE = 10; #DISPPAGE is the number of items displayed per page.
$NUMPAGES = ceil($resultnum / $DISPPAGE); #NUMPAGES to show how many pages you WILL get.
if($result): #Sanity check on query, only runs if valid query.
if($resultnum > 0): #We actually got some rows.
echo "<div align=\"right\">\n\n";
for($i = 1; $i <= $NUMPAGES; $i++): #loop to print << 1 2 3... $NUMPAGES >>
if($i == 1 && $PAGE > 1) #Prints the << first to goto the previous page (not on page 1)
echo "<a href=\"$PHP_SELF?page=".($PAGE - 1)."\" onMouseOver=\"status='Go to the Previous Page';return true;\" onMouseOut=\"status=' ';return true;\">« </a>";
if($i == $PAGE) #Doesn't print a link itself, just prints page number
echo " $i ";
if($i != $PAGE) #Other links that aren't this page go here
echo "<a href=\"$PHP_SELF?page=$i\" onMouseOver=\"status='Go to Page $i';return true;\" onMouseOut=\"status=' ';return true;\"> $i </a>";
if($i == $NUMPAGES && $PAGE != $NUMPAGES) # Link for next page >> (not on last page)
echo "<a href=\"$PHP_SELF?page=".($PAGE + 1)."\" onMouseOver=\"status='Go to the Next Page';return true;\" onMouseOut=\"status=' ';return true;\"> »</a>";
endfor;
echo "\n</div>\n";
echo "\n";
$START = ($PAGE - 1) * $DISPPAGE;
mysql_data_seek($result,$START); #Moves the pointer to right row
#This loop will go until you a) reach $DISPPAGE or b) there aren't anymore entries
for($i = 1; $i <= $DISPPAGE && $ARET = @mysql_fetch_array($result); $i++):
//
// SCRIPT RESULTS SHOWN HERE
//
endfor;
endif;
if($resultnum == 0) #if we get no rows
echo "<div align=\"center\">The database is empty</div>\n";
endif;
if(!$result): # Bogus Query, or mysqld isn't running...
echo "<div align=\"center\">\n";
echo "Either the database is down, or the query was invalid\n";
echo "\n</div>\n";
endif;
The error I get when I put the first script into the above script is
Warning: Offset -10 is invalid for MySQL result index 2 in includes/screenshots.php on line 39
mysql_data_seek($result,$START); #Moves the pointer to right row