开发者

Multiple pages PHP how?

开发者 https://www.devze.com 2022-12-25 13:56 出处:网络
Here I have a problem in this code .. I want to specify the 4 values in each page .. But I can not ... So far there is a problem, I think, in limit

Here I have a problem in this code ..

I want to specify the 4 values in each page .. But I can not ... So far there is a problem, I think, in limit

<?php 

if ( !isset( $_GET["page"] ) ) 
{ 
  $page = 1; 
  include( "connect.php" );  
} else { 
  $page = intval( $_GET['page'] ); 
} 
$max  = 4; 
$from = ($max * $page) - $max; 
$sql  = mysql_query( "
  select *
    from uploads
       , members
       , rooms
   where uploads.MemberID = members.MemberID
     and uploads.RoomID = rooms.RoomID
     and UploadCategory = 'L'
   order by UploadID desc
   limit $from, $max
");  

$num_sql = mysql_num_rows( $sql ); 
$pages   = ceil( $num_sql / $max ); 
$num     = mysql_num_rows( $sql ); 

?> 

<table width="400" border="0" cellspacing="1" cellpadding="0"> 
  <tr> 
    <td>
      <form name="form1" method="post" action=""> 
        <div align="center"> 
          <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> 
            <tr> 
              <td bgcolor="#FFFFFF">&nbsp;</td> 
              <td colspan="4" bgcolor="#FFFFFF"> 
                <p align="center">&开发者_如何学Clt;font size="4"> file</font>
              </td> 
            </tr> 
            <tr> 
              <td align="center" bgcolor="#FFFFFF">#</td> 
              <td align="center" bgcolor="#FFFFFF"><strong>member</strong></td> 
              <td align="center" bgcolor="#FFFFFF"><strong> Name</strong></td> 
            </tr>
          </table> 
        </div>
      </form> 
    </td>
  </tr>
  <?php while( $row = mysql_fetch_array( $sql ) ) : ?>
  <tr> 
    <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['UploadID']; ?>"></td> 
    <td bgcolor="#FFFFFF"> <?php echo $row[MemberName]. "<br />";  ?></td> 
    <td bgcolor="#FFFFFF"> <?php echo $row[UpoadName]."<br />";  ?></td> 
  </tr> 
  <?php endwhile; ?> 
  <tr> 
    <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="delete"></td> 
  </tr>
</table>
<?php 

if ( $page > 1 ) 
{ 
  $prev = $page - 1; 
  echo "<a href=" . $PHP_SELF . "?page=$prev\">prev</a>"; 
} 
for ( $i = 1; $i <= $pages; $i++ )  
{
  echo ( $page == $i )
    ? " [$i] " 
    : " <a href=" . $PHP_SELF . "?page=$i\">$i</a> "; 
} 
if ( $page < $pages ) 
{ 
  $next = $page+1; 
  echo "<a href=" . $PHP_SELF . "?page=$next\">next</a>"; 
} 
?>      
</html> 

thanks a lot

EDIT

Further details

alt text http://up.arab-x.com/Mar10/Xjq83483.jpg

I want to the code as in the picture ..

So that if you click on the number 1 to turn to a new page containing the values 4 and No. 2 if you also turn to a new page containing the 4 other values and so on.

What is wrong with this code even shows me output as in the picture

(((Can anyone help me how can I make code works like the picture ..... Please ... Please

Code works, but not like what I want))))))


Also :

if(!isset($_GET["page"])) 
{ 
    $page=1; 

    include ("connect.php");  
} 
else 
{ 
    $page= intval($_GET['page']); 
}

You include the 'connect.php' script only when the page isn't specified in the query string. Is this correct?


Try using the dictionary with quotes and correct spelling:

echo $row['MemberName']
echo $row['UploadName']

For any better answer, you'd need to include some more information, like Felix already commented...


One major problem I'm seeing in this code is that include ("connect.php"); is inside the if(!isset($_GET["page"])) - but you're running mysql_query regardless.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号